Friday, September 16, 2011

Reverse a Linked List using one pointer.

void reverse(node* temp)
{
     if(temp->next)
     {
        reverse(temp->next);
        temp->next->next = temp;
        temp->next = NULL;
     }
    else
            head = temp;
}


Note: It is not actually one pointer as we are using recursion.

No comments:

Post a Comment