top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to search an element in binary search tree?

+2 votes
282 views
How to search an element in binary search tree?
posted Mar 2, 2016 by Deepa

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote

Function for searching the node in binary Search Tree

node *search(node *root, int keyValue, node **parent) {
       node *temp;
       temp = root;
       while (temp != NULL) {
          if (temp->data == key) {
             printf("\nThe %d Element is Present in BST", temp->data);
             return temp;
          }
          *parent = temp;

          if (temp->data > key)
             temp = temp->lchild;
          else
             temp = temp->rchild;
       }
       return NULL;
    }
answer Mar 13, 2016 by Shivam Kumar Pandey
Similar Questions
+2 votes

How to find the smallest element in a Binary Tree (Not BST)? Sample C/C++ code would be helpful.

+1 vote

How to balance the binary search tree in C/C++? Please provide the necessary explanation also?

...