目錄ios
隊列是一種先進先出的數據結構。數據結構
操做:spa
注:隊列沒有clear方法,程序須要本身實現.net
示例代碼:code
#include <queue> #include <iostream> using namespace std; int main() { queue<int> intQueue; // 入隊 intQueue.push(26); intQueue.push(18); intQueue.push(50); intQueue.push(33); // 隊首 cout << "intQueue.front:" << intQueue.front() << endl; // 隊尾 cout << "intQueue.back:" << intQueue.back() << endl; // 移出隊首元素 intQueue.pop(); cout << "intQueue.front:" << intQueue.front() << endl; // 順序移出 cout << "intQueue :" << endl; while(!intQueue.empty()) { cout << intQueue.front() << " "; intQueue.pop(); } cout << endl; return 0; }運行結果:
intQueue.front:26
intQueue.back:33
intQueue.front:18
intQueue :
18 50 33
blog