Practical 6
Practical 6
thread();
void create();
void insert(node *,node *);
void display_inorder(node *,node *);
void display_preorder(node *,node *);
};
thread::thread()
{
root=NULL;
void thread::create()
{
New=new node;
New->left=NULL;
New->right=NULL;
New->lth=0;
New->rth=0;
cout<<"\n Enter The Element: ";
cin>>New->data;
if(root==NULL)
{
root=New;
dummy=new node;
dummy->data=-999;
dummy->left=root;
root->left=dummy;
root->right=dummy;
}
else
insert(root,New);
}
}
if(New->data>root->data)
{
if(root->rth==0)
{
New->right=root->right;
New->left=root;
root->rth=1;
root->right=New;
}
else
insert(root->right,New);
}
}
}
temp=temp->right;
}
else
{
while(1)
{
if(temp->rth==1)
{
flag=0;
temp=temp->right;
break;
}
else
{
if(temp!=dummy)
{
flag=1;
temp=temp->right;
break;
}
}
}
}
}
}
int main()
{
int choice;
thread th;
do
{
cout<<"\nProgram For Threaded Binary Tree\n";
cout<<"\n1)Create \n2)Display Inorder\n3)Display Preorder\n4)Exit";
cout<<"\nEnter Your Choice: ";
cin>>choice;
switch(choice)
{
case 1:
th.create();
break;
case 2:
th.display_inorder(th.root,th.dummy);
break;
case 3:
th.display_preorder(th.root,th.dummy);
break;
}
}while(choice!=4);
return 0;