#include <iostream>
using namespace std;
#define ulli size_t
template<class T>class Stack {
private:
struct Node {
T data;
Node* next;
};
Node* head;
Node* p;
ulli length;
public:
Stack() {
head = NULL;
length = 0;
p = NULL;
}
void push(T n) {
Node* q = new Node;
q->data = n;
if (head == NULL) {
q->next = head;
head = q;
p = q;
}
else {
q->next = p;
p = q;
}
length++;
}
void pop() {
if (length <= 0) {
abort();
}
Node* q;
T data;
q = p;
data = p->data;
p = p->next;
delete(q);
length--;
}
ulli size() {
return length;
}
T top() {
return p->data;
}
bool empty() {
if (length == 0) {
return true;
}
else {
return false;
}
}
void clear() {
while (length > 0) {
pop();
}
}
};