19cse212-StackArrayTest2-CSEA


Submit solution

Points: 15 (partial)
Time limit: 2.0s
Memory limit: 12M

Author:
Problem type
Allowed languages
C++

This is a simple extension to the problem. You have to fill two functions of the stack which are "Remove all occurrences of top element", and "Find min". In function1 the original stack minus the occurring elements have to be present, and for second problem the stack should remain the same after find min.

Input:
  • Each testcase contains integers N, M, where N is the size of the stack, and M is the number of operations in the test case. Next line will include the size, and next M lines will include series of operations of the following type Character, value, where character indicates the stack operation $P-push, O-pop, T-top, S-size, I-isempty, X - RemoveAllOccurrencesofTop, M - findMin.
Output:

For each testcase, output the result of each operation separated by a newline.

For RemoveAllOccurrencesofTop, use extra stack to help restore original stack after removing occurrences of top element. For find min also use extra stack where necessary.

Since intermediate outputs are tracked in the test cases, do not modify the driver code or the other functions.

Sample Input:
    6
    10
    P 4
    P 6
    P 2
    P 12
    P 4
    X
    P 1
    P 5
    X
    M
Sample Output:
    4 
    4 6 
    4 6 2 
    4 6 2 12 
    4 6 2 12 4 
    <Intermediate trace....>
    Deleted All Occurrences
    6 2 12 
    6 2 12 1 
    6 2 12 1 5 
    <Intermediate trace....>
    Deleted All Occurrences 
    6 2 12 1
    <Intermediate trace....>
    Min 1
    6 2 12 1
EXPLANATION:

The <Intermediate trace....> is a sequence of stack states and operation outputs which is already implemented. It is omitted due to length constrained and to avoid confusions. When using the stack functions these traces will automatically be printed if you call them correctly. Please do not add a print statement "<Intermediate trace....>".


Comments

There are no comments at the moment.