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