File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Polynomial Linked List Reverse Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Beginning Java
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
ExamLab Creator
Saloon Keeper

Joined: Jul 29, 2008
Posts: 3060
    
  38

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 ExamLab - a free SCJP / OCPJP exam simulator
What would SCJP exam questions look like? -- Home -- Twitter -- 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: 19685
    
  20

And otherwise there's still ListIterator:


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
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: 38519
    
  23
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: 50
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
 
Don't get me started about those stupid light bulbs.
 
subject: Polynomial Linked List Reverse