0% found this document useful (0 votes)
4 views

ADSL-4 Inorder Threaded Binary Search Tree-Ass4

A4

Uploaded by

virenlahane7
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

ADSL-4 Inorder Threaded Binary Search Tree-Ass4

A4

Uploaded by

virenlahane7
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

#include <iostream>

using namespace std;

class node

public:

int data,lbit,rbit,flag;

node *left, *right;

node (int x)

data=x;

};

void create1 (node*head,int lr)

int x;

cout<<"\n Enter data:(-1to stop)";

cin>>x;

if (x==-1)

return;

node *temp = new node(x);

if (lr==0)

temp->lbit=head->lbit;

temp->rbit=0;

temp->flag=0;

temp->left=head->left;

temp->right=head;

head->left=temp;

head->lbit=1;

else
{

temp->rbit=head->rbit;

temp->lbit=0;

temp->flag=1;

temp->right=head->right;

temp->left=head;

head->right=temp;

head->rbit=1;

cout<<"\n Enter left child of "<<x;

create1 (temp,0);

cout<<"\n Enter right child of "<<x;

create1(temp,1);

node *create()

node *head=new node(110);

head->left=head->right=head;

head->lbit=0;

head->rbit=1;

create1(head,0);

return head;

node *prenext (node *temp)

if (temp ->lbit==1)

return temp->left;

if(temp->rbit==1)

return temp->right;

while(temp->rbit==0)

temp=temp->right;
return temp->right;

void preorder (node *root)

node *temp=root->left;

while(temp!=root)

cout<<"\n <<temp->data";

temp= prenext (temp);

node *innext(node *temp)

if (temp->rbit==1)

temp=temp->right;

while(temp->lbit==1)

temp=temp->left;

return temp;

else

return temp->right;

void inorder (node *root)

node*temp=root->left;

while(temp->lbit==1)

temp=temp->left;

while(temp!=root)

{cout<<" "<<temp->data;

temp=innext(temp);
}

int main()

node *root=create();

inorder (root);

You might also like