Description
Given a Linked List, separate the nodes at odd positions from the nodes at even positions. Print the nodes at odd positions first, followed by the nodes at even positions.
給一個Linked List,請把奇數位置的node與偶數位置的node分開後,先印出奇數位置node後,再印出偶數位置的node
For example: 1 -> 2 -> 5 -> 7 -> 10 -> 3
例如:1 -> 2 -> 5 -> 7 -> 10 -> 3
The output should be: 1 -> 5 -> 10 -> 2 -> 7 -> 3
則答案應該輸出:1 -> 5 -> 10 -> 2 -> 7 -> 3
**請使用Linked List撰寫!!**我會檢查,用array不予採計。
Input
The input consists of a sequence of numbers, terminated by -1.
輸入包含一串數列,以 -1 結束。
Output
First, print the nodes at odd positions, followed by the nodes at even positions.
請先印出奇數位置的節點,再印出偶數位置的節點。
Sample Input 1
1 2 5 7 10 3 -1
Sample Output 1
1->5->10->2->7->3