reverse a linked list

How can I reverse a linked list recursively with minimum number of temporary pointers

Comments

  1. struct node* reverse(struct node *head)
    {
    struct node *rest = head->next;
    if(rest == NULL)
    return head;
    rest = reverse(head->next);
    head->next->next = head;
    head->next = NULL;

    return rest;
    }

    ReplyDelete

Post a Comment

Popular posts from this blog