C++ STL List
Basic Accuracy: 17.47% Submissions: 2731 Points: 1

Implement different operation on List A i.e. adding an element in front and end, removing an element from the front and end, sorting elements, reversing the list and printing the list.

Input:
The first line of input contains an integer T denoting the no of test cases.For each test case, the first line of input contains an integer Q denoting the no of queries. Then in the next line are Q space separated queries.
A query can be of eight types 
1 x (Adds an element x to the list A at the end and print list A)
2 (Sorts the list A in ascending order and print list A )
3 (Reverses the list A and print list A)
4 (Prints the size of the list A)
5 (Prints space-separated values of the list)
6 (Remove an element from the back of the list and print list A )
7(Remove an element from the front of the list and print list A)
8 x (Adds element x in front of the list and print list A)

Output:
The output for each test case will be according to the query that is performed and if the list is empty output is -1

Constraints:
1<=T<=100
1<=Q<=100

Example:
Input:

1
8
1 5
8 1
3
4
5
6
1 6
7
Output:
5
1 5
5 1 
2
5 1
5
5 6
6

to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.