I am working on a programming assignment and I could use some help understanding the compareTo method.
One of the questions of the assignment is to add an incoming element to a list. If the list is sorted, I am supposed to put the new node in its correct position. The list can be either sorted in an ascending or descending order. I thought I could check which is the order by comparing the head node to the node after (node.getNext()) but I am not sure. The line of code that I am not sure on is the following:
head is the first node is a generic data type T, which has already been added. tp is head.getNext() just to save space and is also a generic data type T, since I am sure I will be typing it again. I did not write a compareTo method on the program because the professor told me that simply call the compareTo method to compare another generic data type. Also, I am not sure on the difference between:
but the assignment requires me to use the first one.
if the head node element is 1 and the next on is 3, what will the output of the if statement be? true or false?