What is the error ? I have done everything right


#1

stack v;

MinStack::MinStack() {
v = stack();
}

void MinStack::push(int x) {

if(v.empty())
{
    v.push(x);
    v.push(x);

}
else
{
    int top=v.top();
    if(x<top)
    {
        v.push(x);
        v.push(x);

    }
    else
    {
        v.push(top);
        v.push(x);

    }
}

// len++;

}

void MinStack::pop() {

if(!v.empty())
{
    v.pop();
    v.pop();
    // len--;
}

}

int MinStack::top() {

if(!v.empty())
return v.top();
else 
return -1;

}

int MinStack::getMin() {

if(!v.empty())
{
    int top=v.top();
    v.pop();
    int min=v.top();
    v.push(top);
    return min;
}
else
 return -1;

}