// Prog: stack.h // definition of the class ifmp::stack #include namespace ifmp { // linked list node struct list_node { int key; list_node* next; list_node (int k, list_node* n = 0) : key (k), next (n) {} }; class stack { public: // default constructor: // POST: *this is an empty stack stack(); // destructor ~stack(); // copy constructor stack (const stack& s); // assignment operator stack& operator= (const stack& s); // POST: key is pushed onto *this void push (int key); // POST: returns whether *this is empty bool empty () const; // PRE: !empty() // POST: top element of *this is returned int top () const; // PRE: !empty() // POST: top element of *this is popped from *this void pop (); // POST: *this is written to o void print (std::ostream& o) const; private: list_node* top_node; // PRE: to == 0 // POST: nodes after from are copied to nodes after to void copy (const list_node* from, list_node*& to); // POST: nodes after from are deleted void clear (list_node* from); }; // output operator std::ostream& operator<< (std::ostream& o, const stack& l); } // end namespace