aspose file tools
The moose likes Java in General and the fly likes Reversing a singly linked list Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Reversing a singly linked list" Watch "Reversing a singly linked list" New topic
Author

Reversing a singly linked list

Wilson Gordon
Ranch Hand

Joined: Apr 07, 2007
Posts: 89
I am looking for some ideas on how to reverse a singly linked list efficiently.

Thanks in advance.
Garrett Rowe
Ranch Hand

Joined: Jan 17, 2006
Posts: 1295
I'm not sure how your linked list is represented internally, but maybe something like this will work:

Does that help at all?
[ June 29, 2007: Message edited by: Garrett Rowe ]

Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
Wilson Gordon
Ranch Hand

Joined: Apr 07, 2007
Posts: 89
Thanks Garrett. That looks like a good algorithm!
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Reversing a singly linked list
 
Similar Threads
get fifth element from last for a Singly linked list
Nth Node from Last ???
delete in a singly linked list
Implement a Singly Linked Sorted List (SortedLinkedList<Comparable>) in Java
Data Structure