Write a iterative function that checks whether an element belongs to a BST.


Difficulty level
This exercise is mostly suitable for students
typedef struct node
{
	element data;
	struct node *left, *right;
} *Btree;

int belongi(Btree B, element e)
{
	while (B)
	{
		if (B->data == e) return 1;
		if (B->data > e) B=B->left;
		else B=B->right;
	}
	return 0;
}

Back to the list of exercises
Looking for a more challenging exercise, try this one !!
Implementing a queue using two stacks