BST End Sem
BST End Sem
h>
#include<stdlib.h>
int main()
{
tree *root=NULL;
int ch,item,a=0,b=0,c=0,d=0;
do{
printf("enter:--\n1 to insert\n2 to inorder\n3 to preorder\n4 to
postorder\n5 to deletion\n6 to biggest element\n7 to smallest element\n8
to count the total nodes\n9 to count the nodes having one child\n10 to
count the nodes having two child\n11 to count the leaf nodes\n12 to find
height\n:::");
scanf("%d",&ch);
switch (ch)
{
case 1:
printf("enter the value:");
scanf("%d",&item);
insert(&root,item);
break;
case 2:
inorder(root);
break;
case 3:
preorder(root);
break;
case 4:
postorder(root);
break;
case 5:
printf("enter the element to delete:");
scanf("%d",&item);
deletion(root,item);
break;
case 6:
bigg(root);
break;
case 7:
small(root);
break;
case 8:
totalnode(root,&a);
printf("count is %d",a);
break;
case 9:
onechild(root,&b);
printf("count is %d",b);
break;
case 10:
twochild(root,&c);
printf("count is %d",c);
break;
case 11:
leafnode(root,&d);
printf("count is %d",d);
break;
case 12:
printf("height is %d",height(root));
break;
default:
printf("wrong choice\n");
}
printf("enter 1 to continue:");
scanf("%d",&ch);
}while(ch==1);
return 0;
}
else if(val>root->info)
{
root->right=deletion(root->right,val);
}
else{
if(root->left==NULL)
{
tree *temp=NULL;
temp=root->right;
free(root);
return temp;
}
else if(root->right==NULL)
{
tree *temp=NULL;
temp=root->left;
free(root);
return temp;
}
else{
tree *temp=NULL;
temp=inordersucc(root->right);
root->info=temp->info;
root->right=deletion(root->right,temp->info);
}
}
return root;
}
else{
if(root!=NULL&&root->right==NULL&&root->left==NULL||root!
=NULL&&root->right==NULL&&root->left!=NULL)
{
printf("%d",root->info);
return;
}
bigg(root->right);
}
}
else{
if(root!=NULL&&root->right==NULL&&root->left==NULL||root!
=NULL&&root->right!=NULL&&root->left==NULL)
{
printf("%d",root->info);
return;
}
small(root->left);
}
}