标签:fine return next nod oid bool 基本算法 ack str
C++ 链栈 基本算法实现
#ifndef LinkStack_h #define LinkStack_h #include <iostream> template <class T> struct Node{ T data; struct Node <T> * next; }; template <class T> class LinkStack{ public: LinkStack() {top = NULL;} ~LinkStack(); void Push (T x); T Pop(); T GetTop(); bool Empty() { return (NULL == top)? true:false;} private: struct Node <T> *top; }; template <class T> void LinkStack<T>::Push (T x){ struct Node <T> * p = new Node <T>; p->data = x; p->next = top; top = p; } template <class T> T LinkStack<T> :: Pop(){ if(Empty()) throw "下溢"; T x = top->data; struct Node <T> * p = top; top = top->next; delete p; return x; } template <class T> LinkStack<T>::~LinkStack(){ while(top){ struct Node <T> *p = top; top = top-> next; delete p; } } template <class T> T LinkStack<T>::GetTop(){ if(Empty()) throw "溢出"; return top->data; } #endif /* LinkStack_h */
标签:fine return next nod oid bool 基本算法 ack str
原文地址:https://www.cnblogs.com/ycbeginner/p/10006402.html