Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Linked List Remove?

 
Luke Gotto
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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;
else
tmp = first.item;
previous = cursor;
first = cursor.next;
length = length -1;

return tmp;


}
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic