Escolar Documentos
Profissional Documentos
Cultura Documentos
#include<string>
#include<conio.h>
#include<cstring>
struct node {
int empid;
double empsalary;
char* empname;
node* left,*right;
};
node* buildbst(node* root, int j, int id, char* name,double salary)
{
if(root==NULL)
{
node* newnode= new node();
newnode->empid=id;
newnode->empname=name;
newnode->empsalary=salary;
newnode->left=newnode->right=NULL;
return newnode;
}
// ---------------------------------------------------page 1
if(root->empid==id)
{
return root;
}
else if(id<=root->empid)
{
root->left=buildbst(root->left,j,id,name,salary);
}
else
{
root->right= buildbst(root->right,j,id,name,salary);
}
}
{ return;
}
postorder(root->left);
postorder(root->right);
main()
int id[]={32,56,93,5,10};
char* name[]={"Raza","sajid","Rabia","sehar","Ali"};
double salary[]= {30000,25000,19230,24000,22200};
int c;
int x=(sizeof(id)/sizeof(*id));
node* root=NULL;
char string[20];
for(int j=0;j<x; j++)
{
root = buildbst(root,j,id[j],name[j],salary[j]);
}
//---------------------------------------------------------------------------------
------------------page 3
p:cout<<endl<<"press 1 to enter data" <<"press 2 to retrieve the record ascending
order"<< "press 3 to retrieve the post order\n"<<"press 4 to exit";
cin >>c;
switch(c)
{
case 1:
{
q: cout<<endl<<"enter id";
cin>>id[x];
cout<<endl<<"enter salary";
cin>>salary[x];
cout<<endl<<"enter name";
cin>>string;
for(int i=0;i<x;i++)
{
if(id[x]==id[i])
{
cout<<endl<<"already exist";
goto y;
}
}
//---------------------------------------------------page 4
name[x]= new char[strlen(string)+1];
strcpy(name[x],string);
for(int j =0;j<(x+1);j++)
{
root=buildbst(root,j,id[j],name[j],salary[j]);
}
cout<< "record is entered";
char sd;
y: cout <<endl<<"do u want to record another record";
sd=getch();
if (sd=='y')
{ goto q;}
else if(sd=='n')
{ goto y;
}
else { cout<<"wrong";
}
break;
}
case 2: //{
ascendingorder(root);
break;
//}
case 3 :
postorder(root);
break;
case 4:
return 0;
break ;
default:
ch= getch();
if(ch=='y')
{
goto p;
}
else
{
cout<<endl<<"\n wrong";
goto y;
}
}