#ifndef stack_h #define stack_h 1 #include template class stack { public: using empty = std::exception; stack(): head(nullptr) {} ~stack() { while (head) pop(); } void push(const T& t) { head = new node{head, t}; } T pop() { if (head) { node *n = head; head = n->next; T t = n->data; delete n; return t; } throw empty(); } private: struct node { node* next; T data; }; node *head; }; #endif // stack_h