GeeCON Prague 2014*
The moose likes Beginning Java and the fly likes getPrev Node method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "getPrev Node method" Watch "getPrev Node method" New topic
Author

getPrev Node method

Devin Henderson
Greenhorn

Joined: Dec 01, 2009
Posts: 16
Cross-Posted here: http://www.dreamincode.net/forums/topic/173326-getprev-node-method/

Hey all.

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!

Any ideas?

Thanks!
Devin Henderson
Greenhorn

Joined: Dec 01, 2009
Posts: 16
Figured it out.

getPrev cannot return null but the Node's info + next can be null. That makes much more sense.

Final code:

 
GeeCON Prague 2014
 
subject: getPrev Node method