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
[ Show ]
Support VoyForums
[ Shrink ]
VoyForums Announcement: Programming and providing support for this service has been a labor of love since 1997. We are one of the few services online who values our users' privacy, and have never sold your information. We have even fought hard to defend your privacy in legal cases; however, we've done it with almost no financial support -- paying out of pocket to continue providing the service. Due to the issues imposed on us by advertisers, we also stopped hosting most ads on the forums many years ago. We hope you appreciate our efforts.

Show your support by donating any amount. (Note: We are still technically a for-profit company, so your contribution is not tax-deductible.) PayPal Acct: Feedback:

Donate to VoyForums (PayPal):

Login ] [ 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 ]


Post a message:
This forum requires an account to post.
[ Create Account ]
[ Login ]
[ Contact Forum Admin ]

"
"
Forum timezone: GMT-8
VF Version: 3.00b, ConfDB:
Before posting please read our privacy policy.
VoyForums(tm) is a Free Service from Voyager Info-Systems.
Copyright © 1998-2019 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