SlideShare a Scribd company logo
Binary Search Tree
#include<stdio.h>                 do
#include<conio.h>                 {
#include<process.h>                  printf("n***MENU***");
#include<alloc.h>                    printf("n1.CREATEn2.INSERT");
struct node                          printf("n3.DELETEn4.DISPLAYn5.EXIT")
{                                    ;
     int data;                       printf("nPLease Enter the Choice...");
     struct node *left,*right;       scanf("%d",&ch);
}*root=NULL,*New,*temp,*p;           switch(ch)
int item;                            {
void create();                              case 1:create();break;
void disp(struct node*,int);                case 2:insert();break;
void del();                                 case 3:del();break;
void insert();                              case 4:disp(root,1);break;
void main()                                 case 5:exit(0);
{                                           default:printf("nInvalid choice...");
     int ch,e;                       }
     clrscr();                    }while(ch!=5);
                                     getch();}
void create()                                        while(temp!=NULL)
{                                                    {
  char ch;                                                 p=temp;
  root=NULL;                                               if(New->data<=temp->data)
  do                                                       temp=temp->left;
  {                                                        else
     New=(struct node *)malloc(sizeof(struct               temp=temp->right;
     node));                                         }
     New->left=New->right=NULL;                       if(New->data<=p->data)
     printf("nEnter the Element...");                p->left=New;
     scanf("%d",&New->data);                          else
     if(root==NULL)                                   p->right=New;
     root=New;                                      }
     else                                           printf("nDo you want add Another(y/n)...");
     {                                              scanf("%c",&ch);
       p=NULL;                                     }while(ch=='y');
       temp=root;                              }


   root = NULL
void create()                                     while(temp!=NULL)
{                                                 {
  char ch;                                              p=temp;
  root=NULL;                                            if(New->data<=temp->data)
  do                                                    temp=temp->left;
  {                                                     else
     New=(struct node *)malloc(sizeof(struct            temp=temp->right;
     node));                                      }
     New->left=New->right=NULL;                    if(New->data<=p->data)
     printf("nEnter the Element...");             p->left=New;
     scanf("%d",&New->data);                       else
     if(root==NULL)                                p->right=New;
     root=New;                                  }
     else                New                    printf("nDo you want add Another(y/n)...");
     {                                          scanf("%c",&ch);
       p=NULL;                                 }while(ch=='y');
       temp=root;                            }


   root = NULL
void create()                                        while(temp!=NULL)
{                                                    {
  char ch;                                                 p=temp;
  root=NULL;                                               if(New->data<=temp->data)
  do                                                       temp=temp->left;
  {                                                        else
     New=(struct node *)malloc(sizeof(struct               temp=temp->right;
     node));                                         }
     New->left=New->right=NULL;                       if(New->data<=p->data)
     printf("nEnter the Element...");                p->left=New;
     scanf("%d",&New->data);         90               else
     if(root==NULL)                                   p->right=New;
     root=New;                                      }
     else              New        90                printf("nDo you want add Another(y/n)...");
     {                                              scanf("%c",&ch);
       p=NULL;                                     }while(ch=='y');
       temp=root;                              }


   root = NULL
void create()                                        while(temp!=NULL)
{                                                    {
  char ch;                                                 p=temp;
  root=NULL;                                               if(New->data<=temp->data)
  do                                                       temp=temp->left;
  {                                                        else
     New=(struct node *)malloc(sizeof(struct               temp=temp->right;
     node));                                         }
     New->left=New->right=NULL;                       if(New->data<=p->data)
     printf("nEnter the Element...");                p->left=New;
     scanf("%d",&New->data);                          else
     if(root==NULL)                                   p->right=New;
     root=New;                                      }
     else                New        90              printf("nDo you want add Another(y/n)...");
     {                                              scanf("%c",&ch);
       p=NULL;                                     }while(ch=='y');
       temp=root;                              }


   root = NULL
void create()                                        while(temp!=NULL)
{                                                    {
  char ch;                                                 p=temp;
  root=NULL;                                               if(New->data<=temp->data)
  do                                                       temp=temp->left;
  {                                                        else
     New=(struct node *)malloc(sizeof(struct               temp=temp->right;
     node));                                         }
     New->left=New->right=NULL;                       if(New->data<=p->data)
     printf("nEnter the Element...");                p->left=New;
     scanf("%d",&New->data);                          else
     if(root==NULL)                                   p->right=New;
     root=New;                                      }
     else                root       90              printf("nDo you want add Another(y/n)...");
     {                                              scanf("%c",&ch);
       p=NULL;                                     }while(ch=='y');
       temp=root;                              }
void create()                                        while(temp!=NULL)
{                                                    {
  char ch;                                                 p=temp;
  root=NULL;                                               if(New->data<=temp->data)
  do                                                       temp=temp->left;
  {                                                        else
     New=(struct node *)malloc(sizeof(struct               temp=temp->right;
     node));                                         }
     New->left=New->right=NULL;                       if(New->data<=p->data)
     printf("nEnter the Element...");                p->left=New;
     scanf("%d",&New->data);                          else
     if(root==NULL)                                   p->right=New;
     root=New;                                      }
     else                root       90              printf("nDo you want add Another
     {                                                (y/n)...");
       p=NULL;                                      scanf("%c",&ch);       y
       temp=root;                                  }while(ch=='y');
                                               }
void create()                                     while(temp!=NULL)
{                                                 {
  char ch;                                              p=temp;
  root=NULL;                                            if(New->data<=temp->data)
  do                                                    temp=temp->left;
  {                                                     else
     New=(struct node *)malloc(sizeof(struct            temp=temp->right;
     node));                                      }
     New->left=New->right=NULL;                    if(New->data<=p->data)
     printf("nEnter the Element...");             p->left=New;
     scanf("%d",&New->data);                       else
     if(root==NULL)                                p->right=New;
     root=New;                                  }
     else                root       90          printf("nDo you want add Another (y/n)...");
     {                                          scanf("%c",&ch);
       p=NULL;                                 }while(ch=='y');
       temp=root;         New                }
void create()                                        while(temp!=NULL)
{                                                    {
  char ch;                                                 p=temp;
  root=NULL;                                               if(New->data<=temp->data)
  do                                                       temp=temp->left;
  {                                                        else
     New=(struct node *)malloc(sizeof(struct               temp=temp->right;
     node));                                         }
     New->left=New->right=NULL;                       if(New->data<=p->data)
     printf("nEnter the Element...");                p->left=New;
     scanf("%d",&New->data);         60               else
     if(root==NULL)                                   p->right=New;
     root=New;                                      }
     else              root       90                printf("nDo you want add Another (y/n)...");
     {                                              scanf("%c",&ch);
       p=NULL;                                     }while(ch=='y');
       temp=root;       New       60
                                               }
void create()                                        while(temp!=NULL)
{                                                    {
  char ch;                                                 p=temp;
  root=NULL;                                               if(New->data<=temp->data)
  do                                                       temp=temp->left;
  {                                                        else
     New=(struct node *)malloc(sizeof(struct               temp=temp->right;
     node));                                         }
     New->left=New->right=NULL;                       if(New->data<=p->data)
     printf("nEnter the Element...");                p->left=New;
     scanf("%d",&New->data);                          else
     if(root==NULL)                                   p->right=New;
     root=New;                                      }
     else                root       90              printf("nDo you want add Another (y/n)...");
     {                                              scanf("%c",&ch);
       p=NULL;                                     }while(ch=='y');
       temp=root;         New       60
                                               }
void create()                                        while(temp!=NULL)
{                                                    {
  char ch;                                                 p=temp;
  root=NULL;                                               if(New->data<=temp->data)
  do                                                       temp=temp->left;
  {                                                        else
     New=(struct node *)malloc(sizeof(struct               temp=temp->right;
     node));                                         }
     New->left=New->right=NULL;                       if(New->data<=p->data)
     printf("nEnter the Element...");                p->left=New;
     scanf("%d",&New->data);                          else
     if(root==NULL)                                   p->right=New;
     root=New;                                      }
     else                root       90              printf("nDo you want add Another (y/n)...");
     {                   temp                       scanf("%c",&ch);
       p=NULL;                                     }while(ch=='y');
       temp=root;         New       60
                                               }

   p=NULL
void create()                                        while(temp!=NULL)
{                                                    {
  char ch;                                                 p=temp;
  root=NULL;                                               if(New->data<=temp->data)
  do                                                       temp=temp->left;
  {                                                        else
     New=(struct node *)malloc(sizeof(struct               temp=temp->right;
     node));                                         }
     New->left=New->right=NULL;                       if(New->data<=p->data)
     printf("nEnter the Element...");                p->left=New;
     scanf("%d",&New->data);                          else
     if(root==NULL)                                   p->right=New;
     root=New;                                      }
     else                root       90              printf("nDo you want add Another (y/n)...");
     {                   temp                       scanf("%c",&ch);
       p=NULL;                                     }while(ch=='y');
       temp=root;         New       60
                                               }

   p=NULL
void create()                                        while(temp!=NULL)
{                                                    {
  char ch;                                                 p=temp;
  root=NULL;                                               if(New->data<=temp->data)
  do                                                       temp=temp->left;
  {                                                        else
     New=(struct node *)malloc(sizeof(struct               temp=temp->right;
     node));                                         }
     New->left=New->right=NULL;                       if(New->data<=p->data)
     printf("nEnter the Element...");                p->left=New;
     scanf("%d",&New->data);                          else
     if(root==NULL)                                   p->right=New;
     root=New;                                      }
     else                root       90  p          printf("nDo you want add Another (y/n)...");
     {                   temp                       scanf("%c",&ch);
       p=NULL;                                     }while(ch=='y');
       temp=root;         New       60
                                               }
void create()                                        while(temp!=NULL)
{                                                    {
  char ch;                                                 p=temp;
  root=NULL;                                               if(New->data<=temp->data) 60<=90
  do                                                       temp=temp->left;
  {                                                        else
     New=(struct node *)malloc(sizeof(struct               temp=temp->right;
     node));                                         }
     New->left=New->right=NULL;                       if(New->data<=p->data)
     printf("nEnter the Element...");                p->left=New;
     scanf("%d",&New->data);                          else
     if(root==NULL)                                   p->right=New;
     root=New;                                      }
     else                root       90  p          printf("nDo you want add Another (y/n)...");
     {                   temp                       scanf("%c",&ch);
       p=NULL;                                     }while(ch=='y');
       temp=root;         New       60
                                               }
void create()                                        while(temp!=NULL)
{                                                    {
  char ch;                                                 p=temp;
  root=NULL;                                               if(New->data<=temp->data)
  do                                                       temp=temp->left;
  {                                                        else
     New=(struct node *)malloc(sizeof(struct               temp=temp->right;
     node));                                         }
     New->left=New->right=NULL;                       if(New->data<=p->data)
     printf("nEnter the Element...");                p->left=New;
     scanf("%d",&New->data);                          else
     if(root==NULL)                                   p->right=New;
     root=New;                                      }
     else                root       90  p          printf("nDo you want add Another (y/n)...");
     {                                              scanf("%c",&ch);
       p=NULL;                                     }while(ch=='y');
       temp=root;         New       60
                                               }

   temp = NULL
void create()                                        while(temp!=NULL)
{                                                    {
  char ch;                                                 p=temp;
  root=NULL;                                               if(New->data<=temp->data)
  do                                                       temp=temp->left;
  {                                                        else
     New=(struct node *)malloc(sizeof(struct               temp=temp->right;
     node));                                         }
     New->left=New->right=NULL;                       if(New->data<=p->data)
     printf("nEnter the Element...");                p->left=New;
     scanf("%d",&New->data);                          else
     if(root==NULL)                                   p->right=New;
     root=New;                                      }
     else                root       90  p          printf("nDo you want add Another (y/n)...");
     {                                              scanf("%c",&ch);
       p=NULL;                                     }while(ch=='y');
       temp=root;         New       60
                                               }

   temp = NULL
void create()                                        while(temp!=NULL)
{                                                    {
  char ch;                                                 p=temp;
  root=NULL;                                               if(New->data<=temp->data)
  do                                                       temp=temp->left;
  {                                                        else
     New=(struct node *)malloc(sizeof(struct               temp=temp->right;
     node));                                         }
     New->left=New->right=NULL;                       if(New->data<=p->data)
     printf("nEnter the Element...");                p->left=New;
     scanf("%d",&New->data);                          else
     if(root==NULL)                                   p->right=New;
     root=New;                                      }
     else                root       90  p          printf("nDo you want add Another (y/n)...");
     {                                              scanf("%c",&ch);
       p=NULL;                                     }while(ch=='y');
       temp=root;             60
                                               }
void create()                                        while(temp!=NULL)
{                                                    {
  char ch;                                                 p=temp;
  root=NULL;                                               if(New->data<=temp->data)
  do                                                       temp=temp->left;
  {                                                        else
     New=(struct node *)malloc(sizeof(struct               temp=temp->right;
     node));                                         }
     New->left=New->right=NULL;                       if(New->data<=p->data)
     printf("nEnter the Element...");                p->left=New;
     scanf("%d",&New->data);                          else
     if(root==NULL)                                   p->right=New;
     root=New;                                      }
     else                root       90              printf("nDo you want add Another
     {                                                (y/n)...");
       p=NULL;                                      scanf("%c",&ch);      n
       temp=root;             60                   }while(ch=='y');
                                               }
void insert()                                     if(New->data<=p->data)
{                                                 p->left=New;
   New=(struct node *)malloc(sizeof(struct        else
   node));                                        p->right=New;
   New->left=New->right=NULL;                    }
   printf("nEnter the Element...");         }
   scanf("%d",&New->data);         70
   if(root==NULL)
   root=New;                                        root        90
   else
   {
     p=NULL;                                               60
     temp=root;
     while(temp!=NULL)                                 New       70
     {
          p=temp;
          if(New->data<=temp->data)
          temp=temp->left;
          else
          temp=temp->right;
     }
void insert()                                     if(New->data<=p->data)
{                                                 p->left=New;
   New=(struct node *)malloc(sizeof(struct        else
   node));                                        p->right=New;
   New->left=New->right=NULL;                    }
   printf("nEnter the Element...");         }
   scanf("%d",&New->data);
   if(root==NULL)
   root=New;                                        root        90
   else
   {
     p=NULL;                                               60
     temp=root;
     while(temp!=NULL)                                New        70
     {
          p=temp;
          if(New->data<=temp->data)
          temp=temp->left;
          else
          temp=temp->right;
     }
void insert()                                     if(New->data<=p->data)
{                                                 p->left=New;
   New=(struct node *)malloc(sizeof(struct        else
   node));                                        p->right=New;
   New->left=New->right=NULL;                    }
   printf("nEnter the Element...");         }
   scanf("%d",&New->data);
   if(root==NULL)
   root=New;                                        root        90
   else                                             temp
   {
     p=NULL;                                               60
     temp=root;
     while(temp!=NULL)                                New        70
     {
          p=temp;
          if(New->data<=temp->data)
          temp=temp->left;
          else
          temp=temp->right;
     }
void insert()                                     if(New->data<=p->data)
{                                                 p->left=New;
   New=(struct node *)malloc(sizeof(struct        else
   node));                                        p->right=New;
   New->left=New->right=NULL;                    }
   printf("nEnter the Element...");         }
   scanf("%d",&New->data);
   if(root==NULL)
   root=New;                                        root        90
   else                                             temp
   {
     p=NULL;                                               60
     temp=root;
     while(temp!=NULL)                                New        70
     {
          p=temp;
          if(New->data<=temp->data)
          temp=temp->left;
          else
          temp=temp->right;
     }
void insert()                                     if(New->data<=p->data)
{                                                 p->left=New;
   New=(struct node *)malloc(sizeof(struct        else
   node));                                        p->right=New;
   New->left=New->right=NULL;                    }
   printf("nEnter the Element...");         }
   scanf("%d",&New->data);
   if(root==NULL)
   root=New;                                        root        90     p
   else                                             temp
   {
     p=NULL;                                               60
     temp=root;
     while(temp!=NULL)                                New        70
     {
          p=temp;
          if(New->data<=temp->data)
          temp=temp->left;
          else
          temp=temp->right;
     }
void insert()                                     if(New->data<=p->data)
{                                                 p->left=New;
   New=(struct node *)malloc(sizeof(struct        else
   node));                                        p->right=New;
   New->left=New->right=NULL;                    }
   printf("nEnter the Element...");         }
   scanf("%d",&New->data);
   if(root==NULL)
   root=New;                                        root        90     p
   else
   {
     p=NULL;                                               60
                                                 temp
     temp=root;
     while(temp!=NULL)                                  New      70
     {
          p=temp;
          if(New->data<=temp->data)
          temp=temp->left;
          else
          temp=temp->right;
     }
void insert()                                     if(New->data<=p->data)
{                                                 p->left=New;
   New=(struct node *)malloc(sizeof(struct        else
   node));                                        p->right=New;
   New->left=New->right=NULL;                    }
   printf("nEnter the Element...");         }
   scanf("%d",&New->data);
   if(root==NULL)
   root=New;                                        root        90     p
   else
   {
     p=NULL;                                               60
                                                 temp
     temp=root;
     while(temp!=NULL)                                  New      70
     {
          p=temp;
          if(New->data<=temp->data)
          temp=temp->left;
          else
          temp=temp->right;
     }
void insert()                                     if(New->data<=p->data)
{                                                 p->left=New;
   New=(struct node *)malloc(sizeof(struct        else
   node));                                        p->right=New;
   New->left=New->right=NULL;                    }
   printf("nEnter the Element...");         }
   scanf("%d",&New->data);
   if(root==NULL)
   root=New;                                        root        90
   else
   {
     p=NULL;                                               60
                                                 temp                p
     temp=root;
     while(temp!=NULL)                                  New      70
     {
          p=temp;
          if(New->data<=temp->data)
          temp=temp->left;
          else
          temp=temp->right;
     }
void insert()                                     if(New->data<=p->data)
{                                                 p->left=New;
   New=(struct node *)malloc(sizeof(struct        else
   node));                                        p->right=New;
   New->left=New->right=NULL;                    }
   printf("nEnter the Element...");         }
   scanf("%d",&New->data);
   if(root==NULL)
   root=New;                                        root        90
   else
   {
     p=NULL;                                               60
                                                                     p
     temp=root;
     while(temp!=NULL)                                New        70
     {
          p=temp;                                     temp = NULL
          if(New->data<=temp->data)
          temp=temp->left;
          else
          temp=temp->right;
     }
void insert()                                     if(New->data<=p->data)
{                                                 p->left=New;
   New=(struct node *)malloc(sizeof(struct        else
   node));                                        p->right=New;
   New->left=New->right=NULL;                    }
   printf("nEnter the Element...");         }
   scanf("%d",&New->data);
   if(root==NULL)
   root=New;                                        root        90
   else
   {
     p=NULL;                                               60
                                                                     p
     temp=root;
     while(temp!=NULL)                                New        70
     {
          p=temp;                                     temp = NULL
          if(New->data<=temp->data)
          temp=temp->left;
          else
          temp=temp->right;
     }
void insert()                                     if(New->data<=p->data)
{                                                 p->left=New;
   New=(struct node *)malloc(sizeof(struct        else
   node));                                        p->right=New;
   New->left=New->right=NULL;                    }
   printf("nEnter the Element...");         }
   scanf("%d",&New->data);
   if(root==NULL)
   root=New;                                        root        90
   else
   {
     p=NULL;                                               60
                                                                     p
     temp=root;
     while(temp!=NULL)                                New        70
     {
          p=temp;                                     temp = NULL
          if(New->data<=temp->data)
          temp=temp->left;
          else
          temp=temp->right;
     }
void insert()                                     if(New->data<=p->data)
{                                                 p->left=New;
   New=(struct node *)malloc(sizeof(struct        else
   node));                                        p->right=New;
   New->left=New->right=NULL;                    }
   printf("nEnter the Element...");         }
   scanf("%d",&New->data);
   if(root==NULL)
   root=New;                                        root        90
   else
   {
     p=NULL;                                               60
     temp=root;
     while(temp!=NULL)                                           70
     {
          p=temp;
          if(New->data<=temp->data)
          temp=temp->left;
          else
          temp=temp->right;
     }
void del()                                         if(p==NULL)
{                                                  {
   struct node *p,*pp,*s,*ps,*child;                 printf("n%d is not found in the Tree",item);
   if(root==NULL)                                    return;
   {                                               }
           printf("nTree is Empty..."); return;   if(p->left!=NULL&&p->right!=NULL)
   }                                               {
   printf("nEnter the data to be deleted...");         ps=p;     s=p->right;
   scanf("%d",&item);                                   while(s->left!=NULL) .
   pp=NULL;                                             {
   p=root;                                                     ps=s;    s=s->left;
   while(p!=NULL && p->data!=item)                      }
   {                                                           root      90
           pp=p;
           if(item<p->data)
           p=p->left;                                               60
           else
           p=p->right;
                                                                           70
   }
void del()                                         if(p==NULL)
{                                                  {
   struct node *p,*pp,*s,*ps,*child;                 printf("n%d is not found in the Tree",item);
   if(root==NULL)                                    return;
   {                                               }
           printf("nTree is Empty..."); return;   if(p->left!=NULL&&p->right!=NULL)
   }                                               {
   printf("nEnter the data to be                       ps=p;     s=p->right;
   deleted...");                                        while(s->left!=NULL) .
   scanf("%d",&item);           90                      {
   pp=NULL;                                                    ps=s;    s=s->left;
   p=root;                                              }
   while(p!=NULL && p->data!=item)                             root                p
                                                                         90
   {
           pp=p;
           if(item<p->data)                                         60
           p=p->left;
           else
                                                                           70
           p=p->right;
   }                                                  pp = NULL
void del()                                         if(p==NULL)
{                                                  {
   struct node *p,*pp,*s,*ps,*child;                 printf("n%d is not found in the Tree",item);
   if(root==NULL)                                    return;
   {                                               }
           printf("nTree is Empty..."); return;   if(p->left!=NULL&&p->right!=NULL)
   }                                               {
   printf("nEnter the data to be deleted...");         ps=p;     s=p->right;
   scanf("%d",&item);                                   while(s->left!=NULL) .
   pp=NULL;                                             {
   p=root;                                                     ps=s;    s=s->left;
   while(p!=NULL && p->data!=item)                      }
   {                                                           root      90        p
           pp=p;
           if(item<p->data)
           p=p->left;                                               60
           else
           p=p->right;
                                                                           70
   }
                                                      pp = NULL
void del()                                         if(p==NULL)
{                                                  {
   struct node *p,*pp,*s,*ps,*child;                 printf("n%d is not found in the Tree",item);
   if(root==NULL)                                    return;
   {                                               }
           printf("nTree is Empty..."); return;   if(p->left!=NULL&&p->right!=NULL)
   }                                               {
   printf("nEnter the data to be deleted...");         ps=p;     s=p->right;
   scanf("%d",&item);                                   while(s->left!=NULL) .
   pp=NULL;                                             {
   p=root;                                                     ps=s;    s=s->left;
   while(p!=NULL && p->data!=item)                      }
   {                                                           root      90        p
           pp=p;
           if(item<p->data)
           p=p->left;                                               60
           else
           p=p->right;
                                                                           70
   }
                                                      pp = NULL
void del()                                         if(p==NULL)
{                                                  {
   struct node *p,*pp,*s,*ps,*child;                 printf("n%d is not found in the Tree",item);
   if(root==NULL)                                    return;
   {                                               }
           printf("nTree is Empty..."); return;   if(p->left!=NULL&&p->right!=NULL)
   }                                               {
   printf("nEnter the data to be deleted...");         ps=p;     s=p->right;
   scanf("%d",&item);                                   while(s->left!=NULL) .
   pp=NULL;                                             {
   p=root;                                                     ps=s;    s=s->left;
   while(p!=NULL && p->data!=item)                      }
   {                                                           root      90        p
           pp=p;
           if(item<p->data)
           p=p->left;                                               60
           else
           p=p->right;
                                                                           70
   }
                                                      pp = NULL
p->data=s->data;        free(p);
  p=s;                      printf("n%d is deleted from Tree...",item);
  pp=ps;                  }
}
if(p->left!=NULL)
child=p->left;
else if(p->right!=NULL)
child=p->right;
else
child=NULL;
if(p==root)
root=child;
else                                root        90       p
{
   if(p==pp->left)
   pp->left=child;                         60
   else
   pp->right=child;
                                                  70
}
                             pp = NULL
p->data=s->data;        free(p);
  p=s;                      printf("n%d is deleted from Tree...",item);
  pp=ps;                  }
}
if(p->left!=NULL)
child=p->left;
else if(p->right!=NULL)
child=p->right;
else
child=NULL;
if(p==root)
root=child;
else                                 root        90      p
{
   if(p==pp->left)
   pp->left=child;           child          60
   else
   pp->right=child;
                                                  70
}
                             pp = NULL
p->data=s->data;        free(p);
  p=s;                      printf("n%d is deleted from Tree...",item);
  pp=ps;                  }
}
if(p->left!=NULL)
child=p->left;
else if(p->right!=NULL)
child=p->right;
else
child=NULL;
if(p==root)
root=child;
else                                 root        90      p
{
   if(p==pp->left)
   pp->left=child;           child          60
   else
   pp->right=child;
                                                  70
}
                             pp = NULL
p->data=s->data;        free(p);
  p=s;                      printf("n%d is deleted from Tree...",item);
  pp=ps;                  }
}
if(p->left!=NULL)
child=p->left;
else if(p->right!=NULL)
child=p->right;
else
child=NULL;
if(p==root)
root=child;
else                                            90        p
{
   if(p==pp->left)
   pp->left=child;           child         60          root
   else
   pp->right=child;
                                                  70
}
                             pp = NULL
p->data=s->data;        free(p);
  p=s;                      printf("n%d is deleted from Tree...",item);
  pp=ps;                  }
}
if(p->left!=NULL)
child=p->left;
else if(p->right!=NULL)
child=p->right;
else
child=NULL;
if(p==root)
root=child;
else
{
   if(p==pp->left)
   pp->left=child;                         60          root
   else
   pp->right=child;
                                                  70
}

More Related Content

What's hot

Os lab file c programs
Os lab file c programsOs lab file c programs
Os lab file c programs
Kandarp Tiwari
 
Lab manual operating system [cs 502 rgpv] (usefulsearch.org) (useful search)
Lab manual operating system [cs 502 rgpv] (usefulsearch.org)  (useful search)Lab manual operating system [cs 502 rgpv] (usefulsearch.org)  (useful search)
Lab manual operating system [cs 502 rgpv] (usefulsearch.org) (useful search)
Make Mannan
 
DataStructures notes
DataStructures notesDataStructures notes
DataStructures notes
Lakshmi Sarvani Videla
 
Data Structures Using C Practical File
Data Structures Using C Practical File Data Structures Using C Practical File
Data Structures Using C Practical File
Rahul Chugh
 
Cn os-lp lab manual k.roshan
Cn os-lp lab manual k.roshanCn os-lp lab manual k.roshan
Cn os-lp lab manual k.roshanriturajj
 
Double linked list
Double linked listDouble linked list
Double linked list
raviahuja11
 
C Prog. - Strings (Updated)
C Prog. - Strings (Updated)C Prog. - Strings (Updated)
C Prog. - Strings (Updated)vinay arora
 
DAA Lab File C Programs
DAA Lab File C ProgramsDAA Lab File C Programs
DAA Lab File C Programs
Kandarp Tiwari
 
The Ring programming language version 1.8 book - Part 75 of 202
The Ring programming language version 1.8 book - Part 75 of 202The Ring programming language version 1.8 book - Part 75 of 202
The Ring programming language version 1.8 book - Part 75 of 202
Mahmoud Samir Fayed
 
The Ring programming language version 1.7 book - Part 73 of 196
The Ring programming language version 1.7 book - Part 73 of 196The Ring programming language version 1.7 book - Part 73 of 196
The Ring programming language version 1.7 book - Part 73 of 196
Mahmoud Samir Fayed
 
design and analysis of algorithm Lab files
design and analysis of algorithm Lab filesdesign and analysis of algorithm Lab files
design and analysis of algorithm Lab files
Nitesh Dubey
 
Ştiri de ultima ora si ultimele ştiri Vdtonline.com
Ştiri de ultima ora si ultimele ştiri Vdtonline.comŞtiri de ultima ora si ultimele ştiri Vdtonline.com
Ştiri de ultima ora si ultimele ştiri Vdtonline.com
Vdtonline.com
 
Daa practicals
Daa practicalsDaa practicals
Daa practicals
Rekha Yadav
 
20070329 Java Programing Tips
20070329 Java Programing Tips20070329 Java Programing Tips
20070329 Java Programing TipsShingo Furuyama
 
C Prog - Strings
C Prog - StringsC Prog - Strings
C Prog - Stringsvinay arora
 
Assignment no39
Assignment no39Assignment no39
Assignment no39Jay Patel
 
The Ring programming language version 1.9 book - Part 45 of 210
The Ring programming language version 1.9 book - Part 45 of 210The Ring programming language version 1.9 book - Part 45 of 210
The Ring programming language version 1.9 book - Part 45 of 210
Mahmoud Samir Fayed
 
C Prog. - Structures
C Prog. - StructuresC Prog. - Structures
C Prog. - Structuresvinay arora
 

What's hot (19)

Os lab file c programs
Os lab file c programsOs lab file c programs
Os lab file c programs
 
Lab manual operating system [cs 502 rgpv] (usefulsearch.org) (useful search)
Lab manual operating system [cs 502 rgpv] (usefulsearch.org)  (useful search)Lab manual operating system [cs 502 rgpv] (usefulsearch.org)  (useful search)
Lab manual operating system [cs 502 rgpv] (usefulsearch.org) (useful search)
 
DataStructures notes
DataStructures notesDataStructures notes
DataStructures notes
 
Data Structures Using C Practical File
Data Structures Using C Practical File Data Structures Using C Practical File
Data Structures Using C Practical File
 
Cn os-lp lab manual k.roshan
Cn os-lp lab manual k.roshanCn os-lp lab manual k.roshan
Cn os-lp lab manual k.roshan
 
Double linked list
Double linked listDouble linked list
Double linked list
 
C Prog. - Strings (Updated)
C Prog. - Strings (Updated)C Prog. - Strings (Updated)
C Prog. - Strings (Updated)
 
DAA Lab File C Programs
DAA Lab File C ProgramsDAA Lab File C Programs
DAA Lab File C Programs
 
The Ring programming language version 1.8 book - Part 75 of 202
The Ring programming language version 1.8 book - Part 75 of 202The Ring programming language version 1.8 book - Part 75 of 202
The Ring programming language version 1.8 book - Part 75 of 202
 
The Ring programming language version 1.7 book - Part 73 of 196
The Ring programming language version 1.7 book - Part 73 of 196The Ring programming language version 1.7 book - Part 73 of 196
The Ring programming language version 1.7 book - Part 73 of 196
 
design and analysis of algorithm Lab files
design and analysis of algorithm Lab filesdesign and analysis of algorithm Lab files
design and analysis of algorithm Lab files
 
Ştiri de ultima ora si ultimele ştiri Vdtonline.com
Ştiri de ultima ora si ultimele ştiri Vdtonline.comŞtiri de ultima ora si ultimele ştiri Vdtonline.com
Ştiri de ultima ora si ultimele ştiri Vdtonline.com
 
Daa practicals
Daa practicalsDaa practicals
Daa practicals
 
20070329 Java Programing Tips
20070329 Java Programing Tips20070329 Java Programing Tips
20070329 Java Programing Tips
 
C Prog - Strings
C Prog - StringsC Prog - Strings
C Prog - Strings
 
C Prog - Array
C Prog - ArrayC Prog - Array
C Prog - Array
 
Assignment no39
Assignment no39Assignment no39
Assignment no39
 
The Ring programming language version 1.9 book - Part 45 of 210
The Ring programming language version 1.9 book - Part 45 of 210The Ring programming language version 1.9 book - Part 45 of 210
The Ring programming language version 1.9 book - Part 45 of 210
 
C Prog. - Structures
C Prog. - StructuresC Prog. - Structures
C Prog. - Structures
 

Viewers also liked

Why to travel?
Why to travel?Why to travel?
Why to travel?
Joanna Mogilnicka
 
всеукраинское объединение «свобода»
всеукраинское объединение       «свобода»всеукраинское объединение       «свобода»
всеукраинское объединение «свобода»Olya Khabarova
 
In lab en_nov2012-smartcitiescongress-smartcities-ict
In lab en_nov2012-smartcitiescongress-smartcities-ictIn lab en_nov2012-smartcitiescongress-smartcities-ict
In lab en_nov2012-smartcitiescongress-smartcities-ict
inLabFIB
 
小山健はなぜ、無名のブログから人気マンガ家になれたのか? 先生:小山健
小山健はなぜ、無名のブログから人気マンガ家になれたのか? 先生:小山健小山健はなぜ、無名のブログから人気マンガ家になれたのか? 先生:小山健
小山健はなぜ、無名のブログから人気マンガ家になれたのか? 先生:小山健
schoowebcampus
 
European legal issues for US enterprise
European legal issues for US enterpriseEuropean legal issues for US enterprise
European legal issues for US enterpriseRob Blamires
 
Revista
RevistaRevista
Revista
Marlon Rojas
 
Manicura casero
Manicura caseroManicura casero
Manicura casero
Diane Gonzales Allende
 
CFR Risk Management &amp; Insurance Services
CFR Risk Management &amp; Insurance ServicesCFR Risk Management &amp; Insurance Services
CFR Risk Management &amp; Insurance ServicesNichole Trobare
 
22stories.com
22stories.com22stories.com
22stories.com
Faraaz Zubairy
 
Positive thinking attitudes_and_beliefs_final_ppt_29.09.2011
Positive thinking attitudes_and_beliefs_final_ppt_29.09.2011Positive thinking attitudes_and_beliefs_final_ppt_29.09.2011
Positive thinking attitudes_and_beliefs_final_ppt_29.09.2011Pallavi Jagtap
 
Hållbar tillväxt
Hållbar tillväxtHållbar tillväxt
Hållbar tillväxt
Kursbazaren
 
Beauty & Health Ltd. - About company
Beauty & Health Ltd. - About companyBeauty & Health Ltd. - About company
Beauty & Health Ltd. - About company
Marina Rogkova
 
Fanpage Ad Proposal
Fanpage Ad Proposal Fanpage Ad Proposal
Fanpage Ad Proposal
Maru Lord
 
【トークセッション】”間の世代”編集者たちと考える、「今求められる編集スキル」 先生:江口 晋太朗・安東 嵩史・桜井 祐・関口 昌弘
【トークセッション】”間の世代”編集者たちと考える、「今求められる編集スキル」 先生:江口 晋太朗・安東 嵩史・桜井 祐・関口 昌弘【トークセッション】”間の世代”編集者たちと考える、「今求められる編集スキル」 先生:江口 晋太朗・安東 嵩史・桜井 祐・関口 昌弘
【トークセッション】”間の世代”編集者たちと考える、「今求められる編集スキル」 先生:江口 晋太朗・安東 嵩史・桜井 祐・関口 昌弘
schoowebcampus
 

Viewers also liked (14)

Why to travel?
Why to travel?Why to travel?
Why to travel?
 
всеукраинское объединение «свобода»
всеукраинское объединение       «свобода»всеукраинское объединение       «свобода»
всеукраинское объединение «свобода»
 
In lab en_nov2012-smartcitiescongress-smartcities-ict
In lab en_nov2012-smartcitiescongress-smartcities-ictIn lab en_nov2012-smartcitiescongress-smartcities-ict
In lab en_nov2012-smartcitiescongress-smartcities-ict
 
小山健はなぜ、無名のブログから人気マンガ家になれたのか? 先生:小山健
小山健はなぜ、無名のブログから人気マンガ家になれたのか? 先生:小山健小山健はなぜ、無名のブログから人気マンガ家になれたのか? 先生:小山健
小山健はなぜ、無名のブログから人気マンガ家になれたのか? 先生:小山健
 
European legal issues for US enterprise
European legal issues for US enterpriseEuropean legal issues for US enterprise
European legal issues for US enterprise
 
Revista
RevistaRevista
Revista
 
Manicura casero
Manicura caseroManicura casero
Manicura casero
 
CFR Risk Management &amp; Insurance Services
CFR Risk Management &amp; Insurance ServicesCFR Risk Management &amp; Insurance Services
CFR Risk Management &amp; Insurance Services
 
22stories.com
22stories.com22stories.com
22stories.com
 
Positive thinking attitudes_and_beliefs_final_ppt_29.09.2011
Positive thinking attitudes_and_beliefs_final_ppt_29.09.2011Positive thinking attitudes_and_beliefs_final_ppt_29.09.2011
Positive thinking attitudes_and_beliefs_final_ppt_29.09.2011
 
Hållbar tillväxt
Hållbar tillväxtHållbar tillväxt
Hållbar tillväxt
 
Beauty & Health Ltd. - About company
Beauty & Health Ltd. - About companyBeauty & Health Ltd. - About company
Beauty & Health Ltd. - About company
 
Fanpage Ad Proposal
Fanpage Ad Proposal Fanpage Ad Proposal
Fanpage Ad Proposal
 
【トークセッション】”間の世代”編集者たちと考える、「今求められる編集スキル」 先生:江口 晋太朗・安東 嵩史・桜井 祐・関口 昌弘
【トークセッション】”間の世代”編集者たちと考える、「今求められる編集スキル」 先生:江口 晋太朗・安東 嵩史・桜井 祐・関口 昌弘【トークセッション】”間の世代”編集者たちと考える、「今求められる編集スキル」 先生:江口 晋太朗・安東 嵩史・桜井 祐・関口 昌弘
【トークセッション】”間の世代”編集者たちと考える、「今求められる編集スキル」 先生:江口 晋太朗・安東 嵩史・桜井 祐・関口 昌弘
 

Similar to Binary Search Tree

Binary search tree.pptx
Binary search tree.pptxBinary search tree.pptx
Binary search tree.pptx
Santhiya S
 
Double linked list
Double linked listDouble linked list
Double linked list
Sayantan Sur
 
Single linked list
Single linked listSingle linked list
Single linked list
Sayantan Sur
 
includestdio.h #includestdlib.h int enqueue(struct node ,.pdf
includestdio.h #includestdlib.h int enqueue(struct node ,.pdfincludestdio.h #includestdlib.h int enqueue(struct node ,.pdf
includestdio.h #includestdlib.h int enqueue(struct node ,.pdf
galagirishp
 
Data structure output 1
Data structure output 1Data structure output 1
Data structure output 1
Balaji Thala
 
Cpds lab
Cpds labCpds lab
program on string in java Lab file 2 (3-year)
program on string in java Lab file 2 (3-year)program on string in java Lab file 2 (3-year)
program on string in java Lab file 2 (3-year)
Ankit Gupta
 
C programms
C programmsC programms
C programms
Mukund Gandrakota
 
Ada file
Ada fileAda file
Ada file
Kumar Gaurav
 
Singly linked list program in data structure - Vtech
Singly linked list program in data structure - VtechSingly linked list program in data structure - Vtech
Singly linked list program in data structure - Vtech
Vtech Academy of Computers
 
Hangman Game Programming in C (coding)
Hangman Game Programming in C (coding)Hangman Game Programming in C (coding)
Hangman Game Programming in C (coding)
hasan0812
 
Datastructures asignment
Datastructures asignmentDatastructures asignment
Datastructures asignmentsreekanth3dce
 
C basics
C basicsC basics
C basicsMSc CST
 
Circular linked list
Circular linked listCircular linked list
Circular linked list
Sayantan Sur
 
Sorting programs
Sorting programsSorting programs
Sorting programsVarun Garg
 

Similar to Binary Search Tree (20)

week-14x
week-14xweek-14x
week-14x
 
Binary search tree.pptx
Binary search tree.pptxBinary search tree.pptx
Binary search tree.pptx
 
Double linked list
Double linked listDouble linked list
Double linked list
 
Single linked list
Single linked listSingle linked list
Single linked list
 
includestdio.h #includestdlib.h int enqueue(struct node ,.pdf
includestdio.h #includestdlib.h int enqueue(struct node ,.pdfincludestdio.h #includestdlib.h int enqueue(struct node ,.pdf
includestdio.h #includestdlib.h int enqueue(struct node ,.pdf
 
Data structure output 1
Data structure output 1Data structure output 1
Data structure output 1
 
Cpds lab
Cpds labCpds lab
Cpds lab
 
program on string in java Lab file 2 (3-year)
program on string in java Lab file 2 (3-year)program on string in java Lab file 2 (3-year)
program on string in java Lab file 2 (3-year)
 
C programms
C programmsC programms
C programms
 
Ada file
Ada fileAda file
Ada file
 
Singly linked list program in data structure - Vtech
Singly linked list program in data structure - VtechSingly linked list program in data structure - Vtech
Singly linked list program in data structure - Vtech
 
C lab manaual
C lab manaualC lab manaual
C lab manaual
 
Hangman Game Programming in C (coding)
Hangman Game Programming in C (coding)Hangman Game Programming in C (coding)
Hangman Game Programming in C (coding)
 
week-4x
week-4xweek-4x
week-4x
 
Datastructures asignment
Datastructures asignmentDatastructures asignment
Datastructures asignment
 
C basics
C basicsC basics
C basics
 
Circular linked list
Circular linked listCircular linked list
Circular linked list
 
Ds 2 cycle
Ds 2 cycleDs 2 cycle
Ds 2 cycle
 
Sorting programs
Sorting programsSorting programs
Sorting programs
 
Ds
DsDs
Ds
 

Recently uploaded

Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
Scholarhat
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
EduSkills OECD
 
Multithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race conditionMultithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race condition
Mohammed Sikander
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Atul Kumar Singh
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
Group Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana BuscigliopptxGroup Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana Buscigliopptx
ArianaBusciglio
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
deeptiverma2406
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
tarandeep35
 

Recently uploaded (20)

Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
 
Multithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race conditionMultithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race condition
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
Group Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana BuscigliopptxGroup Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana Buscigliopptx
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
 

Binary Search Tree

  • 1. Binary Search Tree #include<stdio.h> do #include<conio.h> { #include<process.h> printf("n***MENU***"); #include<alloc.h> printf("n1.CREATEn2.INSERT"); struct node printf("n3.DELETEn4.DISPLAYn5.EXIT") { ; int data; printf("nPLease Enter the Choice..."); struct node *left,*right; scanf("%d",&ch); }*root=NULL,*New,*temp,*p; switch(ch) int item; { void create(); case 1:create();break; void disp(struct node*,int); case 2:insert();break; void del(); case 3:del();break; void insert(); case 4:disp(root,1);break; void main() case 5:exit(0); { default:printf("nInvalid choice..."); int ch,e; } clrscr(); }while(ch!=5); getch();}
  • 2. void create() while(temp!=NULL) { { char ch; p=temp; root=NULL; if(New->data<=temp->data) do temp=temp->left; { else New=(struct node *)malloc(sizeof(struct temp=temp->right; node)); } New->left=New->right=NULL; if(New->data<=p->data) printf("nEnter the Element..."); p->left=New; scanf("%d",&New->data); else if(root==NULL) p->right=New; root=New; } else printf("nDo you want add Another(y/n)..."); { scanf("%c",&ch); p=NULL; }while(ch=='y'); temp=root; } root = NULL
  • 3. void create() while(temp!=NULL) { { char ch; p=temp; root=NULL; if(New->data<=temp->data) do temp=temp->left; { else New=(struct node *)malloc(sizeof(struct temp=temp->right; node)); } New->left=New->right=NULL; if(New->data<=p->data) printf("nEnter the Element..."); p->left=New; scanf("%d",&New->data); else if(root==NULL) p->right=New; root=New; } else New printf("nDo you want add Another(y/n)..."); { scanf("%c",&ch); p=NULL; }while(ch=='y'); temp=root; } root = NULL
  • 4. void create() while(temp!=NULL) { { char ch; p=temp; root=NULL; if(New->data<=temp->data) do temp=temp->left; { else New=(struct node *)malloc(sizeof(struct temp=temp->right; node)); } New->left=New->right=NULL; if(New->data<=p->data) printf("nEnter the Element..."); p->left=New; scanf("%d",&New->data); 90 else if(root==NULL) p->right=New; root=New; } else New 90 printf("nDo you want add Another(y/n)..."); { scanf("%c",&ch); p=NULL; }while(ch=='y'); temp=root; } root = NULL
  • 5. void create() while(temp!=NULL) { { char ch; p=temp; root=NULL; if(New->data<=temp->data) do temp=temp->left; { else New=(struct node *)malloc(sizeof(struct temp=temp->right; node)); } New->left=New->right=NULL; if(New->data<=p->data) printf("nEnter the Element..."); p->left=New; scanf("%d",&New->data); else if(root==NULL) p->right=New; root=New; } else New 90 printf("nDo you want add Another(y/n)..."); { scanf("%c",&ch); p=NULL; }while(ch=='y'); temp=root; } root = NULL
  • 6. void create() while(temp!=NULL) { { char ch; p=temp; root=NULL; if(New->data<=temp->data) do temp=temp->left; { else New=(struct node *)malloc(sizeof(struct temp=temp->right; node)); } New->left=New->right=NULL; if(New->data<=p->data) printf("nEnter the Element..."); p->left=New; scanf("%d",&New->data); else if(root==NULL) p->right=New; root=New; } else root 90 printf("nDo you want add Another(y/n)..."); { scanf("%c",&ch); p=NULL; }while(ch=='y'); temp=root; }
  • 7. void create() while(temp!=NULL) { { char ch; p=temp; root=NULL; if(New->data<=temp->data) do temp=temp->left; { else New=(struct node *)malloc(sizeof(struct temp=temp->right; node)); } New->left=New->right=NULL; if(New->data<=p->data) printf("nEnter the Element..."); p->left=New; scanf("%d",&New->data); else if(root==NULL) p->right=New; root=New; } else root 90 printf("nDo you want add Another { (y/n)..."); p=NULL; scanf("%c",&ch); y temp=root; }while(ch=='y'); }
  • 8. void create() while(temp!=NULL) { { char ch; p=temp; root=NULL; if(New->data<=temp->data) do temp=temp->left; { else New=(struct node *)malloc(sizeof(struct temp=temp->right; node)); } New->left=New->right=NULL; if(New->data<=p->data) printf("nEnter the Element..."); p->left=New; scanf("%d",&New->data); else if(root==NULL) p->right=New; root=New; } else root 90 printf("nDo you want add Another (y/n)..."); { scanf("%c",&ch); p=NULL; }while(ch=='y'); temp=root; New }
  • 9. void create() while(temp!=NULL) { { char ch; p=temp; root=NULL; if(New->data<=temp->data) do temp=temp->left; { else New=(struct node *)malloc(sizeof(struct temp=temp->right; node)); } New->left=New->right=NULL; if(New->data<=p->data) printf("nEnter the Element..."); p->left=New; scanf("%d",&New->data); 60 else if(root==NULL) p->right=New; root=New; } else root 90 printf("nDo you want add Another (y/n)..."); { scanf("%c",&ch); p=NULL; }while(ch=='y'); temp=root; New 60 }
  • 10. void create() while(temp!=NULL) { { char ch; p=temp; root=NULL; if(New->data<=temp->data) do temp=temp->left; { else New=(struct node *)malloc(sizeof(struct temp=temp->right; node)); } New->left=New->right=NULL; if(New->data<=p->data) printf("nEnter the Element..."); p->left=New; scanf("%d",&New->data); else if(root==NULL) p->right=New; root=New; } else root 90 printf("nDo you want add Another (y/n)..."); { scanf("%c",&ch); p=NULL; }while(ch=='y'); temp=root; New 60 }
  • 11. void create() while(temp!=NULL) { { char ch; p=temp; root=NULL; if(New->data<=temp->data) do temp=temp->left; { else New=(struct node *)malloc(sizeof(struct temp=temp->right; node)); } New->left=New->right=NULL; if(New->data<=p->data) printf("nEnter the Element..."); p->left=New; scanf("%d",&New->data); else if(root==NULL) p->right=New; root=New; } else root 90 printf("nDo you want add Another (y/n)..."); { temp scanf("%c",&ch); p=NULL; }while(ch=='y'); temp=root; New 60 } p=NULL
  • 12. void create() while(temp!=NULL) { { char ch; p=temp; root=NULL; if(New->data<=temp->data) do temp=temp->left; { else New=(struct node *)malloc(sizeof(struct temp=temp->right; node)); } New->left=New->right=NULL; if(New->data<=p->data) printf("nEnter the Element..."); p->left=New; scanf("%d",&New->data); else if(root==NULL) p->right=New; root=New; } else root 90 printf("nDo you want add Another (y/n)..."); { temp scanf("%c",&ch); p=NULL; }while(ch=='y'); temp=root; New 60 } p=NULL
  • 13. void create() while(temp!=NULL) { { char ch; p=temp; root=NULL; if(New->data<=temp->data) do temp=temp->left; { else New=(struct node *)malloc(sizeof(struct temp=temp->right; node)); } New->left=New->right=NULL; if(New->data<=p->data) printf("nEnter the Element..."); p->left=New; scanf("%d",&New->data); else if(root==NULL) p->right=New; root=New; } else root 90 p printf("nDo you want add Another (y/n)..."); { temp scanf("%c",&ch); p=NULL; }while(ch=='y'); temp=root; New 60 }
  • 14. void create() while(temp!=NULL) { { char ch; p=temp; root=NULL; if(New->data<=temp->data) 60<=90 do temp=temp->left; { else New=(struct node *)malloc(sizeof(struct temp=temp->right; node)); } New->left=New->right=NULL; if(New->data<=p->data) printf("nEnter the Element..."); p->left=New; scanf("%d",&New->data); else if(root==NULL) p->right=New; root=New; } else root 90 p printf("nDo you want add Another (y/n)..."); { temp scanf("%c",&ch); p=NULL; }while(ch=='y'); temp=root; New 60 }
  • 15. void create() while(temp!=NULL) { { char ch; p=temp; root=NULL; if(New->data<=temp->data) do temp=temp->left; { else New=(struct node *)malloc(sizeof(struct temp=temp->right; node)); } New->left=New->right=NULL; if(New->data<=p->data) printf("nEnter the Element..."); p->left=New; scanf("%d",&New->data); else if(root==NULL) p->right=New; root=New; } else root 90 p printf("nDo you want add Another (y/n)..."); { scanf("%c",&ch); p=NULL; }while(ch=='y'); temp=root; New 60 } temp = NULL
  • 16. void create() while(temp!=NULL) { { char ch; p=temp; root=NULL; if(New->data<=temp->data) do temp=temp->left; { else New=(struct node *)malloc(sizeof(struct temp=temp->right; node)); } New->left=New->right=NULL; if(New->data<=p->data) printf("nEnter the Element..."); p->left=New; scanf("%d",&New->data); else if(root==NULL) p->right=New; root=New; } else root 90 p printf("nDo you want add Another (y/n)..."); { scanf("%c",&ch); p=NULL; }while(ch=='y'); temp=root; New 60 } temp = NULL
  • 17. void create() while(temp!=NULL) { { char ch; p=temp; root=NULL; if(New->data<=temp->data) do temp=temp->left; { else New=(struct node *)malloc(sizeof(struct temp=temp->right; node)); } New->left=New->right=NULL; if(New->data<=p->data) printf("nEnter the Element..."); p->left=New; scanf("%d",&New->data); else if(root==NULL) p->right=New; root=New; } else root 90 p printf("nDo you want add Another (y/n)..."); { scanf("%c",&ch); p=NULL; }while(ch=='y'); temp=root; 60 }
  • 18. void create() while(temp!=NULL) { { char ch; p=temp; root=NULL; if(New->data<=temp->data) do temp=temp->left; { else New=(struct node *)malloc(sizeof(struct temp=temp->right; node)); } New->left=New->right=NULL; if(New->data<=p->data) printf("nEnter the Element..."); p->left=New; scanf("%d",&New->data); else if(root==NULL) p->right=New; root=New; } else root 90 printf("nDo you want add Another { (y/n)..."); p=NULL; scanf("%c",&ch); n temp=root; 60 }while(ch=='y'); }
  • 19. void insert() if(New->data<=p->data) { p->left=New; New=(struct node *)malloc(sizeof(struct else node)); p->right=New; New->left=New->right=NULL; } printf("nEnter the Element..."); } scanf("%d",&New->data); 70 if(root==NULL) root=New; root 90 else { p=NULL; 60 temp=root; while(temp!=NULL) New 70 { p=temp; if(New->data<=temp->data) temp=temp->left; else temp=temp->right; }
  • 20. void insert() if(New->data<=p->data) { p->left=New; New=(struct node *)malloc(sizeof(struct else node)); p->right=New; New->left=New->right=NULL; } printf("nEnter the Element..."); } scanf("%d",&New->data); if(root==NULL) root=New; root 90 else { p=NULL; 60 temp=root; while(temp!=NULL) New 70 { p=temp; if(New->data<=temp->data) temp=temp->left; else temp=temp->right; }
  • 21. void insert() if(New->data<=p->data) { p->left=New; New=(struct node *)malloc(sizeof(struct else node)); p->right=New; New->left=New->right=NULL; } printf("nEnter the Element..."); } scanf("%d",&New->data); if(root==NULL) root=New; root 90 else temp { p=NULL; 60 temp=root; while(temp!=NULL) New 70 { p=temp; if(New->data<=temp->data) temp=temp->left; else temp=temp->right; }
  • 22. void insert() if(New->data<=p->data) { p->left=New; New=(struct node *)malloc(sizeof(struct else node)); p->right=New; New->left=New->right=NULL; } printf("nEnter the Element..."); } scanf("%d",&New->data); if(root==NULL) root=New; root 90 else temp { p=NULL; 60 temp=root; while(temp!=NULL) New 70 { p=temp; if(New->data<=temp->data) temp=temp->left; else temp=temp->right; }
  • 23. void insert() if(New->data<=p->data) { p->left=New; New=(struct node *)malloc(sizeof(struct else node)); p->right=New; New->left=New->right=NULL; } printf("nEnter the Element..."); } scanf("%d",&New->data); if(root==NULL) root=New; root 90 p else temp { p=NULL; 60 temp=root; while(temp!=NULL) New 70 { p=temp; if(New->data<=temp->data) temp=temp->left; else temp=temp->right; }
  • 24. void insert() if(New->data<=p->data) { p->left=New; New=(struct node *)malloc(sizeof(struct else node)); p->right=New; New->left=New->right=NULL; } printf("nEnter the Element..."); } scanf("%d",&New->data); if(root==NULL) root=New; root 90 p else { p=NULL; 60 temp temp=root; while(temp!=NULL) New 70 { p=temp; if(New->data<=temp->data) temp=temp->left; else temp=temp->right; }
  • 25. void insert() if(New->data<=p->data) { p->left=New; New=(struct node *)malloc(sizeof(struct else node)); p->right=New; New->left=New->right=NULL; } printf("nEnter the Element..."); } scanf("%d",&New->data); if(root==NULL) root=New; root 90 p else { p=NULL; 60 temp temp=root; while(temp!=NULL) New 70 { p=temp; if(New->data<=temp->data) temp=temp->left; else temp=temp->right; }
  • 26. void insert() if(New->data<=p->data) { p->left=New; New=(struct node *)malloc(sizeof(struct else node)); p->right=New; New->left=New->right=NULL; } printf("nEnter the Element..."); } scanf("%d",&New->data); if(root==NULL) root=New; root 90 else { p=NULL; 60 temp p temp=root; while(temp!=NULL) New 70 { p=temp; if(New->data<=temp->data) temp=temp->left; else temp=temp->right; }
  • 27. void insert() if(New->data<=p->data) { p->left=New; New=(struct node *)malloc(sizeof(struct else node)); p->right=New; New->left=New->right=NULL; } printf("nEnter the Element..."); } scanf("%d",&New->data); if(root==NULL) root=New; root 90 else { p=NULL; 60 p temp=root; while(temp!=NULL) New 70 { p=temp; temp = NULL if(New->data<=temp->data) temp=temp->left; else temp=temp->right; }
  • 28. void insert() if(New->data<=p->data) { p->left=New; New=(struct node *)malloc(sizeof(struct else node)); p->right=New; New->left=New->right=NULL; } printf("nEnter the Element..."); } scanf("%d",&New->data); if(root==NULL) root=New; root 90 else { p=NULL; 60 p temp=root; while(temp!=NULL) New 70 { p=temp; temp = NULL if(New->data<=temp->data) temp=temp->left; else temp=temp->right; }
  • 29. void insert() if(New->data<=p->data) { p->left=New; New=(struct node *)malloc(sizeof(struct else node)); p->right=New; New->left=New->right=NULL; } printf("nEnter the Element..."); } scanf("%d",&New->data); if(root==NULL) root=New; root 90 else { p=NULL; 60 p temp=root; while(temp!=NULL) New 70 { p=temp; temp = NULL if(New->data<=temp->data) temp=temp->left; else temp=temp->right; }
  • 30. void insert() if(New->data<=p->data) { p->left=New; New=(struct node *)malloc(sizeof(struct else node)); p->right=New; New->left=New->right=NULL; } printf("nEnter the Element..."); } scanf("%d",&New->data); if(root==NULL) root=New; root 90 else { p=NULL; 60 temp=root; while(temp!=NULL) 70 { p=temp; if(New->data<=temp->data) temp=temp->left; else temp=temp->right; }
  • 31. void del() if(p==NULL) { { struct node *p,*pp,*s,*ps,*child; printf("n%d is not found in the Tree",item); if(root==NULL) return; { } printf("nTree is Empty..."); return; if(p->left!=NULL&&p->right!=NULL) } { printf("nEnter the data to be deleted..."); ps=p; s=p->right; scanf("%d",&item); while(s->left!=NULL) . pp=NULL; { p=root; ps=s; s=s->left; while(p!=NULL && p->data!=item) } { root 90 pp=p; if(item<p->data) p=p->left; 60 else p=p->right; 70 }
  • 32. void del() if(p==NULL) { { struct node *p,*pp,*s,*ps,*child; printf("n%d is not found in the Tree",item); if(root==NULL) return; { } printf("nTree is Empty..."); return; if(p->left!=NULL&&p->right!=NULL) } { printf("nEnter the data to be ps=p; s=p->right; deleted..."); while(s->left!=NULL) . scanf("%d",&item); 90 { pp=NULL; ps=s; s=s->left; p=root; } while(p!=NULL && p->data!=item) root p 90 { pp=p; if(item<p->data) 60 p=p->left; else 70 p=p->right; } pp = NULL
  • 33. void del() if(p==NULL) { { struct node *p,*pp,*s,*ps,*child; printf("n%d is not found in the Tree",item); if(root==NULL) return; { } printf("nTree is Empty..."); return; if(p->left!=NULL&&p->right!=NULL) } { printf("nEnter the data to be deleted..."); ps=p; s=p->right; scanf("%d",&item); while(s->left!=NULL) . pp=NULL; { p=root; ps=s; s=s->left; while(p!=NULL && p->data!=item) } { root 90 p pp=p; if(item<p->data) p=p->left; 60 else p=p->right; 70 } pp = NULL
  • 34. void del() if(p==NULL) { { struct node *p,*pp,*s,*ps,*child; printf("n%d is not found in the Tree",item); if(root==NULL) return; { } printf("nTree is Empty..."); return; if(p->left!=NULL&&p->right!=NULL) } { printf("nEnter the data to be deleted..."); ps=p; s=p->right; scanf("%d",&item); while(s->left!=NULL) . pp=NULL; { p=root; ps=s; s=s->left; while(p!=NULL && p->data!=item) } { root 90 p pp=p; if(item<p->data) p=p->left; 60 else p=p->right; 70 } pp = NULL
  • 35. void del() if(p==NULL) { { struct node *p,*pp,*s,*ps,*child; printf("n%d is not found in the Tree",item); if(root==NULL) return; { } printf("nTree is Empty..."); return; if(p->left!=NULL&&p->right!=NULL) } { printf("nEnter the data to be deleted..."); ps=p; s=p->right; scanf("%d",&item); while(s->left!=NULL) . pp=NULL; { p=root; ps=s; s=s->left; while(p!=NULL && p->data!=item) } { root 90 p pp=p; if(item<p->data) p=p->left; 60 else p=p->right; 70 } pp = NULL
  • 36. p->data=s->data; free(p); p=s; printf("n%d is deleted from Tree...",item); pp=ps; } } if(p->left!=NULL) child=p->left; else if(p->right!=NULL) child=p->right; else child=NULL; if(p==root) root=child; else root 90 p { if(p==pp->left) pp->left=child; 60 else pp->right=child; 70 } pp = NULL
  • 37. p->data=s->data; free(p); p=s; printf("n%d is deleted from Tree...",item); pp=ps; } } if(p->left!=NULL) child=p->left; else if(p->right!=NULL) child=p->right; else child=NULL; if(p==root) root=child; else root 90 p { if(p==pp->left) pp->left=child; child 60 else pp->right=child; 70 } pp = NULL
  • 38. p->data=s->data; free(p); p=s; printf("n%d is deleted from Tree...",item); pp=ps; } } if(p->left!=NULL) child=p->left; else if(p->right!=NULL) child=p->right; else child=NULL; if(p==root) root=child; else root 90 p { if(p==pp->left) pp->left=child; child 60 else pp->right=child; 70 } pp = NULL
  • 39. p->data=s->data; free(p); p=s; printf("n%d is deleted from Tree...",item); pp=ps; } } if(p->left!=NULL) child=p->left; else if(p->right!=NULL) child=p->right; else child=NULL; if(p==root) root=child; else 90 p { if(p==pp->left) pp->left=child; child 60 root else pp->right=child; 70 } pp = NULL
  • 40. p->data=s->data; free(p); p=s; printf("n%d is deleted from Tree...",item); pp=ps; } } if(p->left!=NULL) child=p->left; else if(p->right!=NULL) child=p->right; else child=NULL; if(p==root) root=child; else { if(p==pp->left) pp->left=child; 60 root else pp->right=child; 70 }