Code for Reversing a Linked List
by Dinesh[ Edit ] 2013-12-24 18:54:14
Code for Reversing a Linked List
void reverse()
{
if(head == null)
;
Node p = head.next, q = head, r;
while ( p != null )
{
r = q; // r follows q
q = p; // q follows p
p = p.next; // p moves to next node
q.next = r; // link q to preceding node
}
head.next = null;
head = q;
}