Interview Questions For All

Interview Questions For All Who Are Waiting For Jobs

Thursday, July 24, 2008

Search On a Binary Search Tree

11. Write a C program to search for a value in a binary search tree (BST).
Solution:


#include
#include
struct binarysearchtree{
int data;
struct binarysearchtree* left;
struct binarysearchtree* right;
};
typedef struct binarysearchtree* tree;


tree search_node(tree T,int num)
{
if(T==NULL)
{
return NULL;
}
else
{
if(T->data>num)
search_node(T->left,num);
else if(T->data search_node(T->right,num);
return T;
}


}

piot at 7:55 AM

No comments:

Post a Comment

‹
›
Home
View web version
Powered by Blogger.