Reverse a singly 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;
}
}
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;
}
}



Working on machines without understanding them ? Then you should be here..
Geographical location should not become a barrier to Share our knowledge.
Puzzles and Interview question are intended to be discussed here.
0 comments:
Post a Comment