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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!