Reversing singly Linked list, METHOD 2, iterative
SinglyLinkedListNode* reverse(SinglyLinkedListNode* head)
{
SinglyLinkedListNode*prev, *current, *next;
prev=0, next=0;
current=head;
while(current!=0)
{
next=current->next;
current->next=prev;
prev=current;
current=next;
}
head=prev;
return head;
}
Comments
Post a Comment