We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
DoublyLinkedListNode*reverse(DoublyLinkedListNode*llist){//Trying to do this in a way similar to SinglyLinkedList case// Aim is to end up reversing previous and next on all nodesDoublyLinkedListNode*prev=nullptr;DoublyLinkedListNode*current=llist;while(llist&¤t){// first perform the cyclic permutation current = next = prev = currentcurrent=llist->next;llist->next=prev;llist->prev=current;prev=llist;// update previous to llistif(current){llist=current;// update llist to current until the end}}returnllist;}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Reverse a doubly linked list
You are viewing a single comment's thread. Return to all comments →
C++