Stack.h //用"链表"实现栈 //入栈,出栈的时间复杂度为O(1) //复制、清空和遍历栈的时间复杂度为O(n) template<class DT> struct Node{ DT info; Node<DT> *next; }; template<class DT> class Stack { public: Stack():top(NULL) {}; Stack(const Stack<DT> &original); ~Stack(); Stack<DT>& operator=(const Stack<DT> &original); void push(DT element); bool pop(DT &element); bool peek(DT &topEle); //得到栈顶的数据 bool isEmpty() const; void makeEmpty(); private: Node<DT> *top; inline void deepCopy(const Stack<DT> &original); //"深复制" }; Stack.cpp #include "Stack.h" template<class DT> Stack<DT>::Stack(const Stack<DT> &original) { deepCopy(original); } template<class DT> Stack<DT>::~Stack() { makeEmpty(); } template<