Queue To Stack Adapter - Pop Efficient
easy
1. You are required to complete the code of our QueueToStackAdapter class. 2. As data members you've two queues available - mainQ and helperQ. mainQ is to contain data and helperQ is to assist in operations. (This is cryptic - take hint from video) 3. Here is the list of functions that you are supposed to complete 3.1. push -> Should accept new data in LIFO manner. 3.2. pop -> Should remove and return data in LIFO manner. If not available, print "Stack underflow" and return -1. 3.3. top -> Should return data in LIFO manner. If not available, print "Stack underflow" and return -1. 3.4. size -> Should return the number of elements available in the stack. 4. Input and Output is managed for you. Note -> pop, top and size should work in constant time. push should work in linear time.
Constraints
Note -> pop, top and size should work in constant time. push should work in linear time.
Format
Input
Input is managed for you
Output
Output is managed for you
Example
Sample Input
push 10
push 20
push 5
push 8
push 2
push 4
push 11
top
size
pop
top
size
pop
top
size
pop
top
size
pop
top
size
pop
top
size
pop
top
size
pop
quit
Sample Output
11
7
11
4
6
4
2
5
2
8
4
8
5
3
5
20
2
20
10
1
10
Question Video