Searching in a Binary Search Tree
This code to search a value in a Binary Search Tree is not working
completely.
Here *r is a global variable of type struct node.
struct node * searchbt(struct node*bn,int x)
{ if(bn==NULL)
{printf("Element not found.\n");}
if(bn->data==x) {printf("Element found.\n"); r=bn; return r;}
if(bn->data<x) {searchbt((bn->lc),x);}
else {searchbt((bn->rc),x);}
}
No comments:
Post a Comment