Node<E> two = temp.next;
(this is the second code) Does this line mean temp is pointing to the new "two" node?- Since, I want to remove the index node. I am thinking of fiddling with previous nodes. Something like this:
public E remove(int index) { for (int i = 0; i < index - 1 - 1; i++) { temp = temp.next; } temp.previous.next = temp.next; }
public E remove(int index){
for(int i = 0; i < index-1; i++) temp = temp.next;
Node<E> two = temp.next;
//set temp.next to point to the Node next to the Node to be removed
temp.next = two.next;
E elem = two.elem; //store the element to return
two = null; //remove the node
counter--; //decrement size
return elem; //return the element at that position
}
I just corrected my code.
This post has been edited by deprosun: 09 March 2012 - 11:44 AM

New Topic/Question
Reply



MultiQuote








|