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

1 comment:


  1. I have read your article, it is very informative and helpful for me.I admire the valuable information you offer in your articles. Thanks for posting it..
    Amazon Offers
    Credic card offers

    ReplyDelete