Underground - Bhasker V K,the Sandman's Hideout

Thanks for dropping in...I got this running since i needed a place to post info that i found interesting which,i could access online .lotta stuff here might find a few glances ...so make ur self @ home...and hope u find the links/info ur looking for or atleast giv u a hint 'what you should ' be looking for .
Keep Clicking,
Bhasker V K
VoyForums

VoyUser Login optional ] [ Contact Forum Admin ] [ Main index ] [ Post a new message ] [ Search | Check update time | Archives: 1 ]
Subject: Re: binary search


Author:
binar search tree implementation
[ Next Thread | Previous Thread | Next Message | Previous Message ]
Date Posted: 18:37:06 09/21/05 Wed
Author Host/IP: dsl-TN-024.246.247.61.touchtelindia.net/61.247.246.24
In reply to: linked list 's message, "Re: binary search" on 18:35:01 09/21/05 Wed

//Binary search tree implementation by Niranjan Yadla
#include
#include
struct node
{
int data;
struct node *left;
struct node *right;
};
void binsearchtree(struct node **,int);
void delatgivendata(struct node **,int);
inorder(struct node *);
preorder(struct node *);
postorder(struct node *);
void main()
{
int data,choice;
struct node *p;
p=NULL;
clrscr();
while(1)
{
printf("\n1.Add node to the binary search tree");
printf("\n2.Deletion at given data:");
printf("\n3.Exit");
printf("\nEnter the choice");
scanf("%d",&choice);
switch(choice)
{
case 1: printf("\nEnter the data");
scanf("\n%d",&data);
binsearchtree(&p,data);
printf("\n The inorder traversals are:");
printf("\n");
inorder(p);
printf("\n The preorder traversals are:");
printf("\n");
preorder(p);
printf("\nThe post order traversals are:");
printf("\n");
postorder(p);
break;
case 2: printf("\n Please enter the data where you want deleted");
scanf("%d",&data);
delatgivendata(&p);
printf("\nThe inorder traversals are :");
inorder(p);
break;
case 3:exit(0);
}
}
}

void binsearchtree(struct node **q,int data)
{
struct node *temp,*r;
r=*q;
temp=(struct node*)malloc(sizeof(struct node));
temp->data=data;
temp->left=NULL;
temp->right=NULL;
if(r==NULL)
{
*q=temp;
(*q)->left=temp->left;
(*q)->right=temp->right;
}
else
{
if(r->data==data)
printf("\nInvalid input\n");
while(1)
{
if(r->data>data)
{
if(r->left==NULL)
{
r->left=temp;
break;
}
r=r->left;

}
else
{
if(r->right==NULL)
{
r->right=temp;
break;
}
r=r->right;
}
}
}
}
void delatgivendata(struct node **q,int data)
{
struct node *r;
r=*q;

}

inorder(struct node *q)
{
struct node *r;
r=q;
if(r==NULL)
return 0;
else
{
inorder(r->left);
printf("%d\t",r->data);
inorder(r->right);
}
}

preorder(struct node *q)
{
struct node *r;
r=q;
if(r==NULL)
return 0;
else
{
printf("%d\t",r->data);
preorder(r->left);
preorder(r->right);
}
}

postorder(struct node *q)
{
struct node *r;
r=q;
if(r==NULL)
return 0;
else
{
postorder(r->left);
postorder(r->right);
printf("%d\t",r->data);
}
}

[ Next Thread | Previous Thread | Next Message | Previous Message ]


VoyUser Login ] Not required to post.
Post a public reply to this message | Go post a new public message
* Notice: Posting problems? [ Click here ]
* HTML allowed in marked fields.
Message subject (required):

Name (required):

  Expression (Optional mood/title along with your name) Examples: (happy, sad, The Joyful, etc.) help)

  E-mail address (optional):

* Type your message here:

Choose Message Icon: [ View Emoticons ]

Notice: Copies of your message may remain on this and other systems on internet. Please be respectful.

[ Contact Forum Admin ]

"
"
Forum timezone: GMT-8
VF Version: 2.94, ConfDB:
Before posting please read our privacy policy.
VoyForums(tm) is a Free Service from Voyager Info-Systems.
Copyright © 1998-2008 Voyager Info-Systems. All Rights Reserved.
if u want to post ,send an email to bosky101@indiatimes.com ..this is to maintain the integrity of this forum ..cheers
Keep Clicking,
bosky101 Click here to listen to my music station