I am trying to create a complete binary tree using a linked list, instead of arraylist, without comparing node values. What I mean is on inserting a new value, I do not wish
Keep a count of how many items you have in the tree.
Then, to add the n
th item follow the path created by dividing n
repeatedly by two and keeping track of the remainder. Follow the "route" created by the remainder in reverse: where 1 means right and 0 means left.
For example, to add the 11th item:
11/2 = 5 (1)
5/2 = 2 (1)
2/2 = 1 (0)
That means from the root, you'd go left, right, right.