• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Object reference - LinkedList

 
G. Graz
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 21024
78
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic