Description
Please write a program that allows the user to input two sequences, connects them using linked list, interlaces the two sequences into a new linked list, and finally prints out the merged result.
請撰寫一支程式,讓使用者輸入兩個數列,分別使用linked list的方式連接,接著將兩個數列交錯著連接成一個新的linked list,最後再把合併後的結果印出來。
如果兩個數列長度不一樣,則前面交錯印出後剩餘的請直接接在新的串列最後面。
For example:
例如:
Sequence 1: 1 2 3 9 5 7 31 13
第一個數列 1 2 3 9 5 7 31 13
Sequence 2: 8 4 6 10 2
第二個數列 8 4 6 10 2
Merged sequence: 1 8 2 4 3 6 9 10 5 2 7 31 13
則合併後會變為:1 8 2 4 3 6 9 10 5 2 7 31 13
Input
The input consists of two sequences, each terminated by -1.
輸入包含兩個數列,皆以 -1 作為結束。
Output
Print out the merged linked list, following the format shown in the sample output.
請把兩個linked list合併後印出,格式請見範例輸出。
Sample Input 1
1 2 3 9 5 7 31 13 -1
8 4 6 10 2 -1
Sample Output 1
1 8 2 4 3 6 9 10 5 2 7 31 13