In this lab you are given the Node
class, a constructor of Node(int x)
, and the method signature for your insertion method: static Node insert(Node temp, int key)
.
Write your logic in place of the TODO
line in the insert()
's body'. Do not forget to add a value to the given variable key
in the main method. Your method should return a Node value, and that said node value should have the appropriate relationship to a parent node.
Nodes with a repeated value should traverse rightward as if they were greater than the parent node.
You are free to test your code using as many System.out.print()
statements to test your outputs. You can also run our pre-built test cases by going to the Checkmark tab on the left side, and hitting run tests
.
Test cases will check the placement of a new node, and the relationship of the parent to the child node.