11355 - insert and sort   

Description

You are required to do sorting after inserting an element.

Input

The first line contains a non-negative integer N that specifies the number of testcases. The first line of testcases contains a non-negative integer P (0<=op count<65536that specifies the number of operations. The second line for testcases contains operations. Each operations (C, I or S) are separated by a space. Each testcases are separated by a newline character (\n).

C stands for “clear”. Free all nodes in the list.

I stands for “insert and sort”, following by a non-negative integer (insert value, 0<=insert value<65536). Insert a node and sort the list. Sort the list in ascending order. (Hint: You can insert a node on the appropriate position.)

S stands for “show”. Print the value of all nodes in the list. Separate every prints by a whitespace character. If the list is empty, do not print anything.

Output

Print a space after doing S operations (if S has printed something).
e.g. If linked list has 2 elements (1, 2), print "1 2 ".

Sample Input  Download

Sample Output  Download

Partial Judge Code

11355.c

Partial Judge Header

11355.h

Tags




Discuss