#include using namespace std; template class Node{ public: x data; Node *next; }; template class Stack{ public: Stack(); ~Stack(); int StackIsEmpty(); int StackIsFull(); void Push(x e); void Pop(x &e); void Error(); Node* MakeNode(x e); private: Node *top; }; int main(){ Stack s; s.Push(2); s.Push(4); s.Push(6); s.Push(8); int i; s.Pop(i); cout << i << endl; s.Pop(i); cout << i << endl; return 0; } template Stack::Stack(){ top = NULL; } template Stack::~Stack(){ x e; while(!StackIsEmpty()){ Pop(e); } } template int Stack::StackIsEmpty(){ if (top == NULL) return 1; return 0; } template int Stack::StackIsFull(){ return 0; } template void Stack::Push(x e){ Node *q = MakeNode(e); q->next = top; top = q; } template void Stack::Pop(x &e){ Node *q; if (StackIsEmpty()){ Error(); } else{ e = top->data; q = top; top = top->next; delete q; } } template Node* Stack::MakeNode(x e){ Node *q = new Node; q->data = e; q->next = NULL; return q; } template void Stack::Error(){ cout << "Error!!\n"; }