The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Apr 2017 |
| Last Sign in: | 103 Weeks Ago, 3 Days Ago |
| Questions Answered: | 4870 |
| Tutorials Posted: | 4863 |
MBA IT, Mater in Science and Technology
Devry
Jul-1996 - Jul-2000
Professor
Devry University
Mar-2010 - Oct-2016
I wrote function in C to search in avl tree, however it shows all the time the value not found.
Could any one help me to fix it.
int search(struct Node* node, int key){
int ans;
if(node){
if(key==node->key)
ans=1;
else if(key>node->key){
node=node->right;
ans=0;
}else if(key<node->key){
node=node->left;
ans=0;
}else
ans=0;
}else ans =0;
Â
return ans;
}
Â
in the main
int x;
  int key=11;
    x=search(root,key);
    if(x==1){
    printf("nFound %dn",key);
    } else printf("nnot found %dn",key);
-----------