Why it is giving runtime error


#1

MinStack::MinStack() {
}
stack s,minstk;
void MinStack::push(int x) {
s.push(x);
if(minstk.empty())
minstk.push(x);
else if(x<=minstk.top())
minstk.push(x);
}

void MinStack::pop() {
if(minstk.top()==s.top())
minstk.pop();
s.pop();
}

int MinStack::top() {
if(s.size()>0)
return s.top();
else return -1;
}

int MinStack::getMin() {
if(minstk.size()>0)
return minstk.top();
else return -1;
}