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.
Reverse a doubly linked list
Reverse a doubly linked list
Sort by
recency
|
690 Discussions
|
Please Login in order to post a comment
My code in c++:
}
This is the easiest and most efficient way I've found to reverse a doubly linked list in python 3
This problem's C# definition of
DoublyLinkedListNode
andDoublyLinkedList
are buggy.The way the author of this problem defined these classes in C# requires that the classes' fields (i.e.,
prev
,next
,head
,tail
) be set to a non-null values before exiting the constructor, and the classes' constructors aren't written to allow these parameters to be passed in.So it will always fail if you try to solve this problem in C#.
Here's the full exception:
DoublyLinkedListNode* reverse(DoublyLinkedListNode* llist) { DoublyLinkedListNode *curr; curr=llist; while(curr->next!=NULL){ curr=curr->next; } DoublyLinkedListNode *head; head=curr; DoublyLinkedListNode *temp; DoublyLinkedListNode *count=NULL; while(curr!=NULL){ temp=curr->prev; curr->next=temp; curr->prev=count; count=curr; curr=temp;
}hhere is three poimter approach
return head; }