#include<stdio.h>
#include<stdio.h>
#include<stdlib.h>
struct bst
{
struct bst *left;
int info;
struct bst *right;
};
struct bst root;
void create(struct bst*,int);
void preorder(struct bst*);
void postorder(struct bst*);
void del_leaf();
void del_singlechild():
void main()
{
struct bst *p;
int n,c;
char ch;
root=(struct bst*)malloc(sizeof(struct bst));
printf("\nenter the info:");
scanf("%d",&root->info);
root->left=root->right=NULL;
do
{
printf("\ndo you wish to continue:");
ch=getch();
if(ch=='y')
{
p=root;
printf("\nenter the info:");
scanf("%d",&n);
create(p,n);
}
}
while(ch!='n');
do
{
printf("\n1. preorder");
printf("\n2. inorder");
printf("\n4. postorder");
printf("\n5. delete a leaf node");
printf("\n6. exit");
printf("\nenter choice");
scanf("%d",&c);
switch(c)
{
case 1: preorder(root);
break;
case 2: inorder(root);
break;
case 3: postorder(root);
break;
case 4: del_leaf();
break;
case 5: exit(0);
}
}while(c!=6);
}
void create(struct bst*p,int n)
{
struct bst *q;
if(n=p->info)
{
printf("\nduplicate value");
return;
}
else if(n<p->info)
{
if(p->left!=null)
create(p->left,n);
else
{
q=(struct bst*)malloc(sizeof(struct bst));
q->info=n;
q->left=q->right=null;
p->left=q;
}
}
}
if(p->right!=NULL)
create(p->right,n);
else
{
q=(struct bst*)malloc(sizeof(struct bst));
q->info =n;
q->left=q->right=NULL;
p->right=q;
}
}
}
void preorder(struct bst* root)
{
struct bst *p;
p=root;
if(p!=NULL)
{
inorder(p->left);
printf("\t%d",p->info);
}
}
void postorder(struct bst *root)
{
struct bst *p;
p=root;
if(p!->left);
postorder(p->right);
printf("\t%d",p->info);
}
}
void del_leaf()
{
int n;
struct bst *ptr,*par;
printf("n\enter the value of leaf node to delete:");
scanf("%",&n);
par=ptr=root;
while(ptr->info!=n)
{
if(ptr->info<n)
{
par=ptr;
ptr=ptr->right;
}
else
{
par=ptr;
ptr=ptr->left;
}
}
if(ptr->info<par->info)
par->left=NULL;
else
par->right=NULL;
free(ptr);
}
void del_singlechild()
{
int n;
struct bst *ptr,*par,*child,
printf("/enter the value of leaf node to delete:");
scanf("%d",&n);
par=ptr=root;
while(ptr->info=n)
{
par=ptr;
ptr=ptr->right
}
else
{
par=ptr;
ptr=ptr->left;
}
}
if(ptr->left==null)
child=ptr->riht;
else
child=ptr->left;
if(ptr->info(par->info)
par->left=child;
else
par->right=child;
free(ptr);
}
I AM USING TURBO C To Write This Programe & i got 20 error every thing i writed perfect but donno how to make it work today is my pratical of this progrrame pizz make it work :(