This problem asks you:
Step 1: Create a linked list to store a sequence of colors.
Step 2: Insert a node at an appropriate position.
Step 3: Check nodes adjacent to the inserted node on both left and right sides.
Step 4: Delete the checked node if its color is the same as the inserted node.
Step 5: Do Step 3 and Step 4 again until the color of checked node is different.
Note:
For example, if the input is
r r g r e
3
r 1
b 4
g 6
The first sequence is r r g r e, so a linked list is created as
For the statement (r, 1):
Step 2:
Step 3 ~ Step 5 (on the left side):
Step 3 ~ Step 5 (on the right side):
For the statement (b, 4):
Step 2:
Step 3 ~ Step 5:
For the statement (g, 6):
Due to illegal position, ignore this statement.
Finally, the output should be red green red blue.
For OJ submission:
Step 1. Submit only your function.c into the submission block. (Please choose c compiler)
Step 2. Check the results and debug your program if necessary.
The input contains 2 parts:
The output contains the sequence of the remaining colors.