```
struct Node {
int val;
Node *next;
Node (int x, Node *n = NULL): val (x), next (n) {};
```

};

class MinStack {

private :

Node *head;

int min;

public :

MinStack () {head = NULL;}

```
~MinStack () {
Node *p = head;
Node *q;
while (p != NULL) {
q = p;
p = p -> next;
delete q;
}
head = NULL;
}
void push (int x) {
Node *p = new Node (x, head);
if (head == NULL || x < min)
min = x;
head = p;
}
void pop () {
Node *p = head;
head = head -> next;
delete p;
}
int top () {
return head -> val;
}
int getMin () {
return min;
}
```

};