-->
当前位置:首页 > 题库

PROGRAMMING:List de duplication

Luz5年前 (2021-05-10)题库438
Given a linked list L with integer key values, you need to delete the node with repeated absolute values. That is, for each key value K, only the node with the first absolute value equal to K is reserved. At the same time, all deleted nodes must be saved in another linked list. For example, given that l is 21 → - 15 → - 15 → - 7 → 15, you need to output the deleted list 21 → - 15 → - 7 and the deleted list - 15 → 15.
###Input format:
Enter the address of the first node of L in the first line and a positive integer n ($$$Le 10 ^ 5 $$, which is the total number of nodes). The address of a node is a non negative 5-bit integer, and the null address is represented by - 1.
Next, N lines, each of which describes a node in the following format:
```
Address key value next node
```
Where 'address' is the address of the node,' key value 'is an integer whose absolute value does not exceed $$10 ^ 4 $, and' next node 'is the address of the next node.
###Output format:
First output the deleted list, and then output the deleted list. Each node takes up one line and outputs according to the input format.
###Input example:
```in
00100 5
99999 -7 87654
23854 -15 00000
87654 15 -1
00000 -15 99999
00100 21 23854
```
###Output example:
```out
00100 21 23854
23854 -15 99999
99999 -7 -1
00000 -15 87654
87654 15 -1
```







answer:If there is no answer, please comment