生活随笔
收集整理的這篇文章主要介紹了
STL 之栈
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
目錄
重要的數據結構。
操作:
size() ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?返回實際個數empty() ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 判斷是否為空push(item) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 壓棧top() ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 返回棧頂元素pop() ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?將棧頂元素刪除s1.swap(s2) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 將兩個棧元素交互s1 == s1 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?判斷是否相等注:棧沒有clear方法,若程序需要,可以單獨編寫! 示例代碼: #include <stack>
#include <iostream>using namespace std;int main() {stack<int> intStack;// 壓 4個元素入棧intStack.push(16);intStack.push(8);intStack.push(20);intStack.push(3);// 取棧頂元素,并彈棧cout << "top of intStack:" << intStack.top() << endl;intStack.pop();cout << "top of intStack:" << intStack.top() << endl;while(!intStack.empty()) {cout << intStack.top() << " ";intStack.pop();}cout << endl;return 0;
}
運行結果: top of intStack:3
top of intStack:20
20 8 16
轉載于:https://www.cnblogs.com/wjchang/p/3671647.html
總結
以上是生活随笔為你收集整理的STL 之栈的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。