Question: Create a mini stack (in c++) that supports push, pop, top, and retrieving the minimum element using two stacks. push(x) -Push element x onto stack.
Create a mini stack (in c++) that supports push, pop, top, and retrieving the minimum element using two stacks.
push(x) -Push element x onto stack.
pop() -Removes the element on top of the stack.
top() -Get the top element.
getMin() -Retrieve the minimum element in the stack.
Ex.
MinStack minStack;
minStack.push(-1);
minStack.push(0);
minStack.push(-2);
minStack.getMin(); //returns -2
minStack.pop();
minStack.top(); //returns 0
minStack.getMin(); //returns -1
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
