What is the use of constructor in the editorial solution


#1

stacks;
int minEle;
MinStack::MinStack() {
while(!s.empty()) s.pop();
minEle = -1;
}
void MinStack::push(int x) {
if(s.empty()){
s.push(x);
minEle = x;
}
else{
if(x >= minEle) s.push(x);
else{
s.push(2 * x - minEle);
minEle = x;
}
}
}
void MinStack::pop() {
if(s.empty()) return;
if(s.top() < minEle)
minEle = 2 * minEle - s.top();
s.pop();
return;
}
int MinStack::top() {
if(s.empty()) return -1;
if(s.top() >= minEle) return s.top();
else return minEle;
}
int MinStack::getMin() {
if(s.empty()) return -1;
return minEle;
}