Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Originally posted by Barry Gaunt:
What's happening at the end of the list?
Have you stepped through this with a debugger?
Where's the Node class?
[ March 15, 2003: Message edited by: Barry Gaunt ]
Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Originally posted by Eugene Kononov:
Did you consider using standard API for this? Collections.reverse(list) will do the job. Why reinvent the wheel?
Eugene.
Originally posted by Barry Gaunt:
Without seeing what Node.getNext() is doing, we can't tell what's getting returned into curr.
BTW. Have you checked that your input list is correctly linked?
Eugene: I'm guessing Michael's learning data structure concepts. It's one very good way to convince yourself to use Collection and Collections
[ March 15, 2003: Message edited by: Barry Gaunt ]
Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Originally posted by Barry Gaunt:
Looks like you have a situation like:
curr.next <- null; // because prev was null
// and temp is same as curr.
curr <- curr.next; // curr is now set to null
call getNext() through null pointer - Bang!
Cryptic I know, but you get the idea?
[ March 15, 2003: Message edited by: Barry Gaunt ]
Originally posted by michael bradly:
I'm getting a null pointer and am wondering if I am losing a reference somewhere. I am trying to reverse the references in a list.
Assume the list had three items 1) milk 2) eggs 3)butter
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Originally posted by Barry Gaunt:
I would recommend that you do not use null in your algorithm. Use a reference to head instead. If the reference to next (or previous) is to head then you know you are at the end (or front) of the list. An empty list is just head referencing itself in both next and previous directions.
You should get yourself some empty matchboxes, some pins and some coloured thread. Build yourself a list and play with it until the algorithm becomes clear. Then write the code. I would also recommend using BlueJ for such experimentation.
-Barry
[ March 16, 2003: Message edited by: Barry Gaunt ]
Originally posted by Eugene Kononov:
Isn't this beautiful?
Eugene.[/QB]
Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Willie Smits increased rainfall 25% in three years by planting trees. Tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
|