Im doing an assignment on building a binary tree from the preorder and inorder traversals (a char in each Node) and im trying to wrap my brain around how to build the actual tree.
Here is my thought process on how to accomplish this:
- store the first entry in the preorder as the root node
- search the inorder for that entry.
- take the chars to the left of the root node and save them as a char array.
- take the chars to the right of the root node and save them as a char array.
- make a new tree, with the root as the parent and its 2 children being the left and right char arrays.
- keep going recursively until the preorder length is 0.
I have steps 1-4 taken care of, but im not too sure how to properly build my tree, and was wondering if anyone had any pointers. Thank you.