<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                棧的實現,包含的函數有Top(), Push(), Pop(). 簡單易懂的代碼~ 實現代碼: ~~~ #include "iostream" #include "cstdio" #include "cstring" #include "algorithm" using namespace std; template <class T> class Stack { public: virtual bool IsEmpty() const = 0; // 判斷棧是否為空 為空則返回true virtual bool IsFull() const = 0; // 判斷棧是否滿 滿則返回true virtual bool Top(T &x) const = 0; // 返回棧頂元素 操作成功則返回true virtual bool Push(T x) = 0; // 入棧 操作成功則返回true virtual bool Pop() = 0; // 出棧 操作成功則返回true virtual void Clear() = 0; // 清除棧中所有元素 /* data */ }; template <class T> class SeqStack: public Stack<T> { public: SeqStack(int mSize); ~SeqStack() { delete []s; } bool IsEmpty() const { return top == 1; } bool IsFull() const { return top == maxTop; } bool Top(T &x) const; bool Push(T x); bool Pop(); void Clear() { top = -1; } /* data */ private: int top, maxTop; // 棧頂指針 最大棧頂指針 T *s; }; template <class T> SeqStack<T>::SeqStack(int mSize) { maxTop = mSize - 1; s = new T[mSize]; top = 1; } template <class T> bool SeqStack<T>::Top(T &x) const { if(IsEmpty()) { cout << "Stack is empty" << endl; return false; } x = s[top]; return true; } template <class T> bool SeqStack<T>::Push(T x) { if(IsFull()) { cout << "Stack is full" << endl; return false; } s[++top] = x; return true; } template <class T> bool SeqStack<T>::Pop() { if(IsEmpty()) { cout << "Stack is empty" << endl; return false; } top--; return true; } int main(int argc, char const *argv[]) { SeqStack<int> s(5); for(int i = 0; i < 3; ++i) s.Push(i); // s包含0 1 2 int x; if(s.Top(x)) cout << "The top of s is " << x << endl; if(s.Push(x)) cout << "Push successfully" << endl; if(s.Pop()) cout << "Pop successfully" << endl; s.Clear(); return 0; } ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看