Visualize how a doubly linked list is reversed by swapping prev/next pointers!
Hi! I'm Teju 👋 We're going to reverse a doubly linked list in-place (without using extra space).
Input: Number of nodes N, followed by N integer values.
Output: The same list with nodes in reverse order.
Constraints:
• 1 ≤ N ≤ 1000
• Node values: -1000 ≤ value ≤ 1000
Example: 1 ↔ 2 ↔ 3 ↔ 4 ↔ 5 → 5 ↔ 4 ↔ 3 ↔ 2 ↔ 1
We simply swap the prev and next pointers of every node and update head at the end!
Example original list
Enter the number of nodes and values to build the list...
Reversed Linked List Elements: