is it not enough to declare the struct variables as shown?? getting error that some are undeclared pls help...
insertion on a binary search tree....
#include<stdio.h>
#include<stdlib.h>
struct node
{
int data;
struct node *lchild,*rchild;
}*ptr,*new;
void insert(int item,struct node *root)
{
ptr=root;
while(ptr!=NULL)
{
if(item>ptr->data)
{
if(ptr->rchild!=NULL)
insert(item,rchild);
else
{
new=(struct node*)malloc(sizeof(struct node));
ptr->data=item;
}
}
if(item<ptr->data)
{
if(ptr->lchild!=NULL)
insert(item,lchild);
else
{
new=(struct node*)malloc(sizeof(struct node));
ptr->data=item;
}
}
}
}
void main()
{
int ch,item;
char y;
do
{
printf(" main menu \nInsert\n2.delete\n3.preorder\n4.inorder\n5.postorder\n6.hight\n7.count\n Enter your choice : ");
scanf("%d",&ch);
switch(ch)
{
case 1:
printf("enter the number :");
scanf("%d",&item);
if(root==NULL)
{
new=(struct node*)malloc(sizeof(struct node));
root->data=item;
root->rchild=NULL;
root->lchild=NULL;
}
else
insert(item,root);
break;
/* case 2:
delete();
break;
case 3:
preorder();
break;
case 4:
inorder();
break;
case 5:
postorder();
break;
case 6:
hight();
break;
case 7:
count();
break; */
default:
printf("Invalid choice \n");
break;
}
printf(" press y to continue : ");
scanf("%s",&y);
}while(y=='y');
}