You are viewing a single comment's thread. Return to all comments →
def reverse(llist): head = None # Initialize the reversed list head curr = llist # Start with the original list head while curr: next_node = curr.next # Store next node curr.next = head # Reverse next pointer curr.prev = next_node # Reverse prev pointer head = curr # Move head to current node curr = next_node # Move to next node return head # Return the reversed list head
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 →