#ifndef stack_h #define stack_h 1 template class stack { public: ~stack() { while (!empty()) pop(); } // NOT THREAD-SAFE!!! bool empty() const { return head == nullptr; } // FOR HOW LONG??? void push(T t) { head = new node{head, t}; // LOCK-FREE??? } T pop() { node *n = head; head = n->next; // UNDEFINED BEHAVIOR!!! T t = n->data; // UNDEFINED BEHAVIOR!!! delete n; // LOCK-FREE??? return t; } private: struct node { node *next = nullptr; T data; }; node *head = nullptr; }; #endif // stack_h