• + 0 comments

    My code in c++:

    DoublyLinkedListNode* reverse(DoublyLinkedListNode* llist) {
        if(llist == NULL) return NULL;
        else if(llist->next == NULL) return llist;
       ``
        DoublyLinkedListNode* re = new DoublyLinkedListNode(llist->data);
        llist = llist->next;
        while(llist != NULL){
            DoublyLinkedListNode* x = new DoublyLinkedListNode(llist->data);
            x->next = re;
            re->prev = x;
            re = x;
    
        llist = llist->next;
    }
    return re;
    

    }