C++ STL Deque | Practice | GeeksforGeeks

Implement different operations on a Deque i.e. adding an element in front and end, removing an element from front and end, sort the Deque, reverse the Deque, getting the size of the Deque. 
Input Format:
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 followed by Q space separated queries.
A query can be of the following types:
1 x (Adding an element in front of the deque and printing the deque)
2 x (Adding an element in last of the deque and printing the deque)
3 (Removing the element from the front of the deque and printing the deque)
4 (Removing the element from the last of the deque and printing the deque)
5 (Sorting the deque and printing the deque)
6 (Reversing the deque and printing the deque)
7 (Printing the deque)
8 (Returning the size of the deque)
9 (Printing the element that is in front of the deque)
10 (Printing the element that is in back of the deque)
Output Format:
For each test case, the output is according to the query Q performed and if the deque is empty the output is -1.
Your Task:
This is a function problem, so you only need to complete the provided functions.
Constraints:
1<=T<=100
1<=Q<=100
Example:
Input:
1
10
1 6
2 9
9
10
5
6
7
8
3
4
Output:
6 
6 9 
6
9
6 9 
9 6 
9 6 
2
6 
-1
0
anushkasiddhu003
This comment was deleted.
+2
Sumit Pardhiya1 year ago
Sumit Pardhiya
void print(deque<int> &A){//Your code here//if the queue is empty then print -1 with a newline//else print the elements from front to backif(A.empty())cout<<"-1";else{    for(auto it=A.begin();it!=A.end();it++)    {        cout<<*it<<" ";    }}cout<<endl; }="" void="" add_in_front(deque<int=""> &A,int x){//Your code hereA.push_front(x);}void add_in_back(deque<int> &A,int x){//Your code hereA.push_back(x);}void remove_from_back(deque <int> &A){   //Your code here   if(A.empty())     cout<<"-1";   else   {       A.pop_back();   }void remove_from_front(deque<int> &A){   //Your code here   if(A.empty())   cout<<"-1";   else   {       A.pop_front();   }}void sort(deque<int> &A){//Your code heresort(A.begin(),A.end());}void reverse(deque<int> &A){//Your code herereverse(A.begin(),A.end());}int size(deque<int> &A){//Your code herereturn A.size();}int element_at_front(deque <int> &A){    //Your code here    return A.front();}int element_at_back(deque <int> &A){    //Your code here    return A.back();
}
We strongly recommend solving this problem on your own before viewing its editorial. Do you still
                    want to view the editorial?
 Login to access your submissions. 

Problem


Contest

Reset the IDE using the second button on the top right corner.
Avoid using static/global variables in your code as your code is tested against multiple test cases and these tend to retain their previous values.
Passing the Sample/Custom Test cases does not guarantee the correctness of code. On submission, your code is tested against multiple test cases consisting of all possible corner cases and stress constraints.
You can access the hints to get an idea about what is expected of you as well as the final solution code.
You can view the solutions submitted by other users from the submission tab.