```
struct StackNode{
int val;
StackNode *next;
StackNode(int x) : val(x), next(NULL) {}
};
class MinStack {
private:
StackNode* Top;
StackNode* Min;
public:
void push(int x) {
if(Top == NULL){
Top = new StackNode(x);
x;
}
else
{
StackNode *NewTop = new StackNode(x);
NewTop->next = Top;
Top = NewTop;
if(x < Min->val)
Min = Top;
}
}
void pop() {
if (Top != NULL){
if (Top == Min)
Min = Top->next;
Top = Top->next;
StackNode *minTmp = Top;
while (minTmp != NULL){
if (minTmp->val < Min->val)
Min = minTmp;
minTmp = minTmp->next;
}
}
}
int top() {
return Top->val;
}
int getMin() {
return Min->val;
}
};
```

Thanks!