Searching in a BST
Procedure :
Iterative Function :
struct Node *BSTsearch(struct Node *ptr, int key) {
while (ptr != NULL) {
if (key == ptr -> data) {
return ptr;
} else if (key < ptr -> data) {
ptr = ptr -> left;
} else {
ptr = ptr -> right;
}
}
return NULL;
}Recursive Function :
Last updated