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
The entire basis of a binary tree is on comparing values and sending them left or right down the tree.
Therefore, it is impossible to create a binary tree without comparisons.
But you did say upon insertion
, so you could add the item to the end of the list, and then sort it when you call for the tree. Like this:
list.add(value); //Just add the item to the end
call(); //This method would sort the list into a tree appropriately.
This option also allows you to change the type of tree dynamically, since you could add a parameter to call()
that specifies a tree type.