C++ || 2 stacks || remember to initialize in constructor(lost 100 pts because of this)


#1
stack<int> y;
stack<int> minstack;
int minimum=INT_MAX;

MinStack::MinStack() {
stack p;
stack q;
y=p;
minstack=q;
minimum=INT_MAX;
}

void MinStack::push(int x) {
if(y.empty())
{
y.push(x);
minimum=x;
minstack.push(minimum);
}
else
{
y.push(x);
minimum=min(minstack.top(),y.top());
minstack.push(minimum);
}

}

void MinStack::pop() {
if(!y.empty())
{
y.pop();
minstack.pop();
}

}

int MinStack::top() {
if(y.empty())
{
return -1;
}
else
{
return y.top();
}
}

int MinStack::getMin() {
if(y.empty())
{
return -1;
}
else
{
return minstack.top();
}
}