This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Linked List Remove? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Linked List Remove?" Watch "Linked List Remove?" New topic

Linked List Remove?

Luke Gotto

Joined: Apr 04, 2008
Posts: 2
When i run this it removes all of the elemets of the list except the last one... Any ideas why it is not geting to the last node?

public E remove() // delete link with given key
E tmp;
tmp = null;
cursor = first;
previous = first;

if (cursor == null)
return null;
tmp = first.item;
previous = cursor;
first =;
length = length -1;

return tmp;

marc weber

Joined: Aug 31, 2004
Posts: 11343

Sorry, I really can't figure out how this is intended to work. I think it might help if you explained the steps in English. It's a good way to check your own logic, and it would give us a clear idea of what you're expecting to happen.

(Code Tags with clean indentation would also help.)

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
subject: Linked List Remove?
Similar Threads
[resolved] Problem with generic methods
really weird linked list error, please help!!
Need help to convert from Con List to Link List
Iterator Pattern
Generics: cannot make a static reference to the non-static type