//Implementation of Binary Tree Using Linked List
#include<iostream>
using namespace std;
class Node{
public:
Node *left,*right;
int data;
public:
Node(){
left=right=NULL;
data=0;
}
Node(int data){
this->data = data;
left=right=NULL;
}
};
Node *makeTree(){
int data;
cout<<"\nEnter Value of Node : (-1 for No Node) : ";
cin>>data;
if(data==-1){
return NULL;
}
Node *newNode = new Node();
newNode->data = data;
cout<<"\nEnter Left Child of : "<<newNode->data;
newNode->left = makeTree();
cout<<"\nEnter Right Child of : "<<newNode->data;
newNode->right = makeTree();
return newNode;
}
void preorder(Node *root){
if(root==NULL)
return;
cout<<root->data<<" ";
preorder(root->left);
preorder(root->right);
}
void inorder(Node *root){
if(root==NULL)
return;
inorder(root->left);
cout<<root->data<<" ";
inorder(root->right);
}
void postorder(Node *root){
if(root==NULL)
return;
postorder(root->left);
postorder(root->right);
cout<<root->data<<" ";
}
int main(){
Node *root = makeTree();
cout<<"\nPreorder Traversal is : ";
preorder(root);
cout<<"\nInorder Traversal is : ";
inorder(root);
cout<<"\nPostOrder Traversal is :";
postorder(root);
return 0;
}