Vous êtes sur la page 1sur 1

//initially diff1 is root->data key

Search(node * root, int key, int diff1)



{
struct node * temp;
int diff2= abs(root->data key);

if(root==NULL) //if tree is null
return;


if(root->data == key) //if key is found at root itself
return root;


if(key < root->data)

{
if(root->left==Null) //left tree is null
return root;
else
{
node * temp = root->left
if (diff2<diff1)
{diff2= diff1;
Search(root->left, key, diff2);}
else
return temp;
}


Else

{
if(!root->right) //right tree is null
return root;

else
{
node * temp = root->right;
if (diff2<diff1)
{diff2= diff1;
Search(root->right, key, diff2);}
else
return temp;


}
}

Vous aimerez peut-être aussi