Maintaing list order in binary tree.
- by TheBigO
Given a sequence of numbers, I want to insert the numbers into a balanced binary tree such that when I do a preorder traversal on the tree, it gives me the sequence back.
How can I construct the insert method corresponding to this requirement?
Remember that the tree must be balanced, so there isn't a completely trivial solution. I was trying to do this with a modified version of an AVL tree, but I'm not sure if this can work out.