{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

BINARY SEARCH TREE PRINTOUT

BINARY SEARCH TREE PRINTOUT -...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
#include<stdio.h> #include<conio.h> /* RISHI AGARWAL           BINARY SEARCH TREE    ROLL NO 02    SE CMPN A */ struct node {struct node *left;  int data;  struct node *right; }; void insert(struct node **root,int v) {  struct node *q;  q=*root;  if(q==NULL)  {   *root=(struct node *)malloc(sizeof(struct node));   (*root)->data=v;   (*root)->left=NULL;   (*root)->right=NULL;   return;  }  if(v<q->data)  insert(&q->left,v);  else  insert(&q->right,v); } void search(struct node **root,int v,int *found,struct node  **par,struct node **x) {  struct node *q;  q=*root;  while(q!=NULL)  {   if(q->data==v)   {    *found=1;    *x=q;    return;   }   *par=q;
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
  if(v<q->data)   q=q->left;   else   q=q->right;  } } void del(struct node **root,int v) {  int found=0;  struct node *x,*parent,*xsucc;  parent=x=NULL;  if(*root==NULL)  {   printf("Tree is empty\n");   return;  }  search(root,v,&found,&parent,&x);  if(found==0)  {   printf("Node not found\n");   return;  }  if(parent==NULL)  {   if((x->left!=NULL)&&(x->right==NULL))
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}