Segregate Odd and Even Nodes
Rearrange a linked list so all nodes at odd positions come before nodes at even positions.
Input format
The first line contains N — the number of nodes. The second line contains the N node values in list order.
Output format
Rearrange so all nodes at odd positions (1st, 3rd, …) come before nodes at even positions (2nd, 4th, …), preserving relative order, and print the list.
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
1 3 5 2 4Example 2
Input
1
9Expected output
9