I am a problem trying to figure out the assignment method breakdown that our instructor gave us.
The method breakdown is:
In getPrev for the OrderedList you are going to return the reference to the Node that has the largest Object that is less than the one passed to the parameter, thus you will be using the compareTo method to loop while the Object in the list is "less than" the parameter. (Of course, in delete in the OrderedList, once you know the previous node, you still need to make sure the following value is the one you wanted to delete. Note that getPrev might return the reference to the last node, so be careful about accessing the predecessor’s next node!)
In the OrderedList, getPrev will never return null. Make sure you understand why it will not return null.
Alright, so I understand everything until the last part about getPrev never being able to return null. Here is my code:
So the problem is that there are times that getPrev is called where headNode (which is a class variable of the List class that calls the OrderedList class) is null. If the headNode is null, then getPrev is going to return null. But, as the instructions state, getPrev cannot return null.
Just a little confused!
posted 5 years ago
Figured it out.
getPrev cannot return null but the Node's info + next can be null. That makes much more sense.