#include
using namespace std;
class node
{
public:
int data;
node* left;
node* right;
node(int d)
{
data =d;
left= NULL;
right=NULL;
}
};
node* buildTree()
{
int d;
cin>>d;
if(d== -1)
{
return NULL;
}
node* root= new node(d);
root->left=buildTree();
root->right=buildTree();
return root;
}
// FOR PRINTING THE PREORDER TRAVERSAL ORDER
void printPre(node * root)
{
if(root==NULL)
{
return;
}
cout<<“INORDER TRAVERSAL OUTPUT:”<data<<" “;
printPre(root->left);
printPre(root->right);
}
// FOR PRINTING THE INORDER TRAVERSAL ORDER
void printIn(node * root)
{
if(root== NULL)
{
return;
}
printIn(root-> left);
cout<<“PREORDER TRAVERSAL OUTPUT”<data<<” ";
printIn(root->right);
}
// FOR PRINTING THE POSTORDER TRAVERSAL
void printPost(node * root)
{
if(root== NULL)
{
return;
}
printPost(root->left);
printPost(root->right);
cout<<“POSTORDER TRAVERSAL OUTPUT”<data<<" ";
}
int main()
{
node * root= buildTree();
printPre(root);
cout<<endl;
printIn(root);
cout<<endl;
printPost(root);
cout<<endl;
}