• + 2 comments

    how does every node's prev gets changed here ?

    my C++ recursive solution

    Node* Reverse(Node* head)
    {
        // Complete this function
        // Do not write the main method. 
        if(head==NULL){
            return head;
        }
        else if(head->next==NULL){
            head->next=head->prev;
            head->prev=NULL;
            return head;
        }
        Node *prevPtr=head->prev;
        Node *nextPtr=head->next;
        head->next=prevPtr;
        head->prev=nextPtr;
        return Reverse(nextPtr);
    }