template struct elem { T inf; elem *link; }; template class stack { public: stack(); ~stack(); stack(stack const &); stack& operator=(stack const &); void push(T const &); int pop(T &); bool empty() const; void print(); private: elem *start; void delstack(); void copystack(stack const &); }; template stack::stack() { start = NULL; } template stack::~stack() { delstack(); } template stack::stack(stack const &r) { copystack(r); } template stack& stack::operator=(stack const &r) { if (this != &r) { delstack(); copystack(r); } return *this; } template void stack::push(T const &x) { elem *p = start; start = new elem; start->inf = x; start->link = p; } template int stack::pop(T &x) { if (start) { x = start->inf; elem *p = start; start = start->link; delete p; return 1; } return 0; } template bool stack::empty() const { return start == NULL; } template void stack::print() { T x; while (pop(x)) cout< void stack::delstack() { elem *p; while (start) { p = start; start = start->link; delete p; } } template void stack::copystack(stack const &r) { if (r.start) { elem *p = r.start, *q = NULL, *s = NULL; start = new elem; start->inf = p->inf; start->link = NULL; q = start; p = p->link; while (p) { s = new elem; s->inf = p->inf; q->link = s; q = s; p = p->link; } q->link = NULL; } else start = NULL; }