Part 15 of 15 in Binary Trees  

Construct a binary tree given its inorder and preorder traversals by animeshn

Problem statement

In this problem, you need to construct a binary tree given its inorder and preorder traversals. You will have to write a function

Node* buildTree(int[], int [], int)
which accepts the inorder and preorder traversals of a binary tree and the last argument denotes the number of nodes in the tree. You may assume that the traversals given will always be correct. You may write any other functions to support the buildTree function if you need it. Just make sure you have written those functions above the buildTree function.

new node is declared in C++ as:
Node* newNode = new Node();


To try out your code



Sign in

Sign up