queue即佇列,一種先進先出的資料結構,
#include<iostream> #include<queue> using namespace std; int main() { //構造 queue<int> q; //一般空參構造 //入隊 q.push(2); q.push(6); q.push(8); cout << q.size() << endl; //size:3 //取隊尾 cout << q.back() << endl; //輸出:8 //queue不能遍歷,只能一個一個出隊 while (!q.empty()) { //輸出2 6 8 先進先出 cout << q.front() << ' '; //取隊首,不會出隊 q.pop(); //出隊,無回傳值 } cout << endl << q.size() << endl; //size:0 return 0; }
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/43009.html
標籤:C++
上一篇:用C++實作:Sine之舞
