利用STl實現隊列
阿新 • • 發佈:2017-09-29
ont ack cnblogs 後來 ring 先進後出 元素 algorithm out
隊列的使用註意:1.無法輸出數列,可以返回隊尾或隊首。 2.隊列是先進後出,相當於一群人排隊,隊列頭的人先走,後來的人站在隊尾。 3.利用STL來實現普通隊列: q.pop() 刪除隊首 q.front() 返回隊首 q.back() 返回隊尾 q.push(x) 隊尾加入一個元素x q.empty() 隊列為空則為真為0 q.size() 返回隊列長度,元素個數 #include<algorithm> #include <cstring> #include <queue> using namespace std; #define maxn 2000 queue<int>a; int main(){ // q.pop(); q.push(); q.empty(); q.size(); //q.front(); q.back(); int n,x; cin>>n; for(int i=1;i<=n;i++){ cin>>x; a.push(x); } cout<<a.front(); }
利用STl實現隊列