//Binary Search Tree
#include<stdio.h>
#include<stdlib.h>
typedef struct node
{
int key;
struct node *left;
struct node* right;
}node;
void printIO(node * n)
{ if(!n)return;
if(n->left)
printIO(n->left);
printf("%d.",n->key);
if(n->right)
printIO(n->right);
}
node * create(node * n,int k)
{ n=(node *)malloc(sizeof(node));
n->key=k;
n->left=NULL;
n->right=NULL;
return n;
}
node * insert(node * n,int k)
{
node * root=n;
if(n==NULL)
{n= create(n,k);printf("%d.",k);}
else if(k>n->key){n->right= insert(n->right,k);}
else if(k<=n->key){n->left= insert(n->left,k);}
return n;
}
int main()
{
node * root=NULL;
printf("\n Inserting Sequence\n");
root=insert(root,202);root=insert(root,125);root=insert(root,255);root=insert(root,313);
root=insert(root,116);root=insert(root,222);root=insert(root,150);
printf("\n In Order of Created Binary Search tree\n");
printIO(root);
printf("\n");
return 0;
}
#include<stdio.h>
#include<stdlib.h>
typedef struct node
{
int key;
struct node *left;
struct node* right;
}node;
void printIO(node * n)
{ if(!n)return;
if(n->left)
printIO(n->left);
printf("%d.",n->key);
if(n->right)
printIO(n->right);
}
node * create(node * n,int k)
{ n=(node *)malloc(sizeof(node));
n->key=k;
n->left=NULL;
n->right=NULL;
return n;
}
node * insert(node * n,int k)
{
node * root=n;
if(n==NULL)
{n= create(n,k);printf("%d.",k);}
else if(k>n->key){n->right= insert(n->right,k);}
else if(k<=n->key){n->left= insert(n->left,k);}
return n;
}
int main()
{
node * root=NULL;
printf("\n Inserting Sequence\n");
root=insert(root,202);root=insert(root,125);root=insert(root,255);root=insert(root,313);
root=insert(root,116);root=insert(root,222);root=insert(root,150);
printf("\n In Order of Created Binary Search tree\n");
printIO(root);
printf("\n");
return 0;
}