Program To Implement Binary Search Tree in C
Program To Implement Binary Search Tree in C
#include<stdio.h>
struct BT
{
int data;
return ;
}
if ( ptr->data == no )
return ( 1 );
if ( ptr->data > no )
return ( search( ptr->left, no ) );
else
return ( search( ptr->right, no ) );
}
main()
{
struct BT * root;
int ch, d, no, f;
root = NULL;
while ( ch != 6 )
{
printf( "\n 1.Insert\n 2.Search\n 3.Inorder\n 4.Preorder\n 5.Postorder\n 6.Exit\n" );
printf( "\n Enter the choice:" );
scanf( "%d", &ch );
switch ( ch )
{
case 1:
printf( "Enter the data:" );
scanf( "%d", &d );
insert( &root, d );
break;
case 2:
printf( "Enter the node:" );
scanf( "%d", &no );
f = search( root, no );
if ( f == 0 )
printf( "Node is not present" );
else
printf( "Node is present" );
break;
case 3:
inorder( root );
break;
case 4:
preorder( root );
break;
case 5:
postorder( root );
break;
case 6:
break;
}
}
}
/******************OUTPUT******************
1.Insert
2.Search
3.Inorder
4.Preorder
5.Postorder
6.Exit
1.Insert
2.Search
3.Inorder
4.Preorder
5.Postorder
6.Exit
1.Insert
2.Search
3.Inorder
4.Preorder
5.Postorder
6.Exit
1.Insert
2.Search
3.Inorder
4.Preorder
5.Postorder
6.Exit
1.Insert
2.Search
3.Inorder
4.Preorder
5.Postorder
6.Exit