Stack To Queue Adapter - Add Efficient
1. You are required to complete the code of our StackToQueueAdapter class. The class should mimic the behaviour of a Queue and implement FIFO semantic.Input Format
2. Here is the list of functions that are written in the class
2.1. add -> Accepts new data if there is space available in the underlying array or
print "Queue overflow" otherwise.
2.2. remove -> Removes and returns value according to FIFO, if available or print
"Queue underflow" otherwise and return -1.
2.3. peek -> Returns value according to FIFO, if available or print "Queue
underflow" otherwise and return -1.
2.4. size -> Returns the number of elements available in the queue.
3. Input and Output is managed for you.
Input is managed for youOutput Format
Output is managed for youQuestion Video
Note -> add and size should work in constant time. remove and peek should work in linear time.Sample Input
add 10Sample Output
add 20
add 30
add 40
add 50
remove
remove
add 60
add 70
peek
remove
peek
remove
peek
remove
peek
remove
peek
remove
peek
remove
quit
10
20
30
30
40
40
50
50
60
60
70
70
Queue underflow
Queue underflow
-
Asked in Companies
-
Related Topics
Video Solution
Code Solution
{ }
{ }
Run