I wrote this simple program in C to generate binary search tree, but i am unable to go beyond level 0. Note that I have not incorporated the printing part.
#include<stdio.h>
#include<malloc.h>
struct node {
int data;
struct node *lc;
struct node *rc;
}*start,*link,*tmp;
int a[100];
int main()
{
int i,n,flag;
start=NULL;
printf("how many integers you wish to enter\n");
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
tmp=(struct node*)malloc(sizeof(struct node));
tmp->data=a[i];
tmp->lc=NULL;
tmp->rc=NULL;
flag=0;
if(start==NULL) start=tmp;
else {
link=start;
while(link!=NULL)
{
if(link->data==a[i]) {printf ("The element already exists");flag=1;break;}
else if(a[i]>link->data) {link=link->rc;printf("rc\n");}
else if(a[i]<link->data) {link=link->lc;printf("lc\n");}
}
if(flag==0) link=tmp
}
}
getch();
return 0;
}