Write a recursive 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 belongr(Btree B, element e)
{
if (!B) return 0;
if (B->data == e) return 1;
if (B->data > e) return belongr(B->left, e);
return belongr(B->right, e);
}
Back to the list of exercises
Looking for a more challenging exercise, try this one !!
Kth smallest element in an array using QuickSort