Sunday, 21 April 2019

To implement binary search tree using linked list.

//To implement binary search tree using linked list.
int count = 0;
typedef struct Btree{
     int data;
     struct Btree *left;
     struct Btree *right;
struct Btree* insert(struct Btree *bt,int n){
         bt= (struct Btree *) malloc(sizeof(struct Btree));
     else if(n<=bt->data)
     bt->left = insert(bt->left,n);
     bt->right = insert(bt->right,n);
     return bt;

int searchElement(struct Btree *bt,int item){
         else if(item>bt->data)
         else if(item == bt->data)
         return count;
        return 0;
int main(){
     struct Btree *bt;
     int loc;
     int item;
        count = 0;
        printf("which operation you want to perform....\n");
        printf("1. Insert an element.\n");
        printf("2. Search an element.\n");
        int op;
        int sEle;
        case 1:
             printf("Enter a number.\n");
             bt = insert(bt,item);
        case 2:
             printf("Enter an number for search.");
             loc = searchElement(bt,sEle);
                printf("Element not found.");
                printf("element found at %d ",loc);
            printf("Please choose correct option...\n\n");

1 comment:

  1. It's very useful blog post with informative and insightful content and i had good experience with this information.I have gone through CRS Info Solutions Home which really nice. Learn more details About Us of CRS info solutions. Here you can see the Courses CRS Info Solutions full list. Find Student Registration page and register now. Go through Blog post of crs info solutions. I just read these Reviews of crs really great. You can now Contact Us of crs info solutions. You enroll for Pega Training at crs info solutions.


Featured post

In all other cases the driver is not insured. If the marital status, sex and age of the driver are the inputs, write a program to determine whether the driver is to be insured or not.

  #include #include int main() { char ms;   printf("Is Driver married (Y/N): ");  scanf("%c",&ms);   if(ms=='y&#...

Popular Posts