Popular Posts

Monday, March 14, 2011

Reverse a linked list


public void reverse() 
{
Node current = head;
head = null ; //set head to null
while(current != null)
{
Node save = current;
//Interchange the pointers
current = current.next;
save.next = head;
head = save;
}
}
http://www.ihas1337code.com/2010/04/reversing-linked-list-iteratively-and.html

No comments:

Post a Comment