Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions