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 Object reference - LinkedList Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Object reference - LinkedList " Watch "Object reference - LinkedList " New topic
Author

Object reference - LinkedList

G. Graz
Ranch Hand

Joined: Oct 23, 2006
Posts: 30
Hello , I am working on a reverse method that will reverse the objects of the Doubly LinkedList via the pointers . To accomplish this I have to use "next" & "previous" . I am confident that I am on the right track with my method but would like a second set of eyes. All I am really looking for is a thumbs up or down on the my logic behind it , what I am doing is drawing an actual linklist on a whiteboard and running this method manual . Thank you for any suggestions. And yes , I know this can be accomplished much easier but the goal is to have a better understanding of object reference .





Miklos Szeles
Ranch Hand

Joined: Oct 21, 2008
Posts: 142
Hi,

Is it just a pseudo algorithm? IT is not Java(At least part of it). this is a reserved keyword, so you can't use that. I'm guessing you want to use a ListIterator type variable at that place. There's no such thing as .next and .previous. They are methods:
.next()
.previous()
It's called LinkedList not LinkList
...

So it's a little bit hard to read what you want to do in the algorithm.
You're while loop will run endlessly (if current != null at the beggining) since it's value never changed.
Please make it understandable, and then we can help. Use real Java code, or forget about java and describe the algorithm(in this case it's not a java question, but anyway I'll try to help with it).
So please modify it to be Java code or describe it line by line.


Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38851
    
  23
I am afraid I shall have to disagree with you, Miklos Szeles. Doubly-linked lists have references to other nodes, usually called next and previous.
Miklos Szeles
Ranch Hand

Joined: Oct 21, 2008
Posts: 142
I know that a doubly linked list nodes has pointers to previous and next elements, but when we talk about Java, I don't think there's a Doubly-linked list implementation which has a public previous and next field. At least it wouldn't be a good OOP practice. Or am I missed something?
I was talking about the ListIterator
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18840
    
  40

Miklos Szeles wrote:I know that a doubly linked list nodes has pointers to previous and next elements, but when we talk about Java, I don't think there's a Doubly-linked list implementation which has a public previous and next field. At least it wouldn't be a good OOP practice. Or am I missed something?
I was talking about the ListIterator


I think the OP is referring to a home growned linked list (homework assignment), and not the LinkedList class.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
 
Don't get me started about those stupid light bulbs.
 
subject: Object reference - LinkedList