This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Polynomial Linked List Reverse Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Polynomial Linked List Reverse" Watch "Polynomial Linked List Reverse" New topic
Author

Polynomial Linked List Reverse

mike fusc
Greenhorn

Joined: Mar 07, 2010
Posts: 15
I add to add together polynomials and got through it but the solution comes out backwards. How would I go about reversing the Nodes in the lsit

Devaka Cooray
Saloon Keeper

Joined: Jul 29, 2008
Posts: 2691
    
    3

Basically, you need to iterate from the last node to the first node by backtracking. To ShowSomeEffort, can you show us what have you done up to now?


Author of ExamLab (Download) - the free mock exam kit for SCJP / OCPJP
Home Page -- Twitter Profile -- JavaRanch FAQ -- How to Ask a Question
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

When the output is wrong then you should try to fix the problem and not solve its symptoms. If it's not wrong then you can reverse the List with Collections.reverse().


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19216

And otherwise there's still ListIterator:


SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

With the small difference that Collections.reverse actually changes your List while the ListIterator only changes your "view" on that List.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32651
    
    4
Is it possible to iterate the List, push all the elements onto a stack, then pop them and add them to a new List?
Stephan Mueller
Ranch Hand

Joined: May 05, 2010
Posts: 49
Campbell Ritchie wrote:Is it possible to iterate the List, push all the elements onto a stack, then pop them and add them to a new List?


Is that a rethorical question ?
At least, it lead me to find http://download.oracle.com/javase/6/docs/api/java/util/Stack.html , which I haven't seen by now. And with JavaSE6, erm 5, it's
a generic Class! whoohooo


1. Make it run - 2. Make it run correctly - 3. Make it pretty OR fast/small - 4. ??? - 5. Profit
 
I agree. Here's the link: http://jrebel.com/download
 
subject: Polynomial Linked List Reverse
 
Similar Threads
Will Bill Gates pay you?
Ben Souther reaches 1000 posts
Passed SCJD = 91%
Best Paymasters in NCR
Passed SCJP = 68%