BINARY SEARCH TREE PRINTOUT

BINARY SEARCH TREE PRINTOUT - #include...

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 DocumentRight 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;  }
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.

This note was uploaded on 10/25/2010 for the course CMPN SEM3 taught by Professor Thakur during the Fall '07 term at University of Mumbai.

Page1 / 6

BINARY SEARCH TREE PRINTOUT - #include...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online