Professional Documents
Culture Documents
Tree10 Build A Binary Tree by Using Preorder and Inorder Traversal Sequence
Tree10 Build A Binary Tree by Using Preorder and Inorder Traversal Sequence
#include<iostream>
class Node{
public:
Node *left,*right;
int data;
public:
Node(){
left=right=NULL;
data=0;
}
Node(int data){
this->data = data;
left=right=NULL;
}
};
if(start>end){
return NULL;
}
if(start == end){
return node;
}
int position = search(inorder,start,end,current);
node->left = makeTree(preorder,inorder,start,position-1);
node->right = makeTree(preorder,inorder,position+1,end);
return node;
}
void inorderPrint(Node *root){
if(root==NULL)
return;
inorderPrint(root->left);
cout<<" "<<root->data;
inorderPrint(root->right);
}
int main(){
inorderPrint(root);
return 0;
}