Reverse a Doubly Linked List
Reverse the nodes of a doubly linked list in-place.
Input format
The first line contains N. The second line contains the N node values of a doubly linked list.
Output format
Reverse the list in-place and print it from the new head, space-separated.
Constraints
- Values fit in a 64-bit signed integer
- Trailing whitespace and a trailing newline are ignored by the judge
Read from stdin, write to stdout. Sample cases below show the exact format.
Sample cases
Example 1
Input
5
1 2 3 4 5Expected output
5 4 3 2 1Example 2
Input
1
3Expected output
3