This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

getPrev Node method

 
Devin Henderson
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Figured it out.

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

Final code:

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic