This is a program..to create and search for Binary Tree..
An error is occoured for class tree ..as " Too many types in declaration".
I would be glad if anyone can tell me to solve this problem.
Thanks for all the support.

#include<iostream.h>
#include<conio.h>
struct node
{
int data;
node *right;
node *left;
}
class tree
{
private:
node *start,*cur,*temp;
public:
tree()
{
start=NULL;
}
void create(int x);
void search(int x);

};


void main()
{
tree obj;
cout<<"\n1: Create new Binary tree.\n";
cout<<"2: Search values from Binary tree.\n";
cout<<"Enter you Choice:";
int s,opt,val;
cin>>opt;
if(opt==1)
{
cout<<"\n\nEnter 10 values.\n";
for(int i=0;i<10;i++)
{
cin>>val;
obj.create(val);
}
}
else
{
cout<<"\n\nEnter value to search?";
cin>>s;
obj.search(s);

}
}
void tree::search(int x)
{
if(start==NULL)
{ cout<<"Tree is empty.."; getch(); return;
}
else
{
cur=start;
while(cur!=NULL)
{
if(cur->data==x)
{
cout<<"\nData found.."; getch(); return;
}
if(cur->data<x)
cur=cur->right;
else
cur=cur->left;
}
if(cur==NULL)
{
cout<<"\nValue not found";
getch();
}
}
}

void tree::create(int x)
{
if(start==NULL)
{
start=new node;
start->data=x;
start->right=NULL;
start->left=NULL;
}
else
{
node *parent;
cur=start;
while(cur!=NULL)
{
if(cur->data==x)
{
cout<<"\nValue already exist..";
return;
}
if(cur->data<x)
{ parent=cur; cur=cur->right;
}
else
{ parent=cur; cur=cur->left;
}
}
temp=new node;
temp->data=x;
temp->right=NULL;
temp->left=NULL;
if(parent==NULL)
parent=temp;
else if(parent->data>x)
parent->left=temp;
else
parent->right=temp;
}
}

Hi Abdul.
Could you show more about the problem by taking a photo?
I think it will be useful for everyone here to help you.

Structure definitions need to be terminated by a semicolon:

struct node
{
    int data;
    node *right;
    node *left;
};

Without it, the compiler is treating the class definition as part of the structure definition, which is a syntax error.

This article has been dead for over six months. Start a new discussion instead.