Skip to content

Latest commit

 

History

History
31 lines (21 loc) · 530 Bytes

File metadata and controls

31 lines (21 loc) · 530 Bytes

Method 1

bool search(Node* root, int x) {
   
    if(!root) return false;
    
    if(root->data==x)  return true;
    
    if(x>root->data)
       return search(root->right,x);
 
    return search(root->left,x);
        
}

Method 2

bool search(Node* root, int x) {
    
    while(root!=NULL && root->data!=x)
    {
        root= x>root->data? root->right : root->left;
    }
    return root;
}