Search On a Binary Search Tree

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

#include<stdio.h>
#include<stdbool.h>
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<num)
search_node(T->right,num);
return T;
}


}



Click Here For More Questions

No comments:

Post a Comment