天天看點

C++STL之queue隊列容器

queue隊列容器是一個先進先出的線性表,元素的插入隻能在隊尾,元素的删除隻能在隊頭。

#include<iostream>
#include<queue>
using namespace std;

int main()
{
	queue<int> q;
	q.push(1);
	q.push(2);
	q.push(3);
	q.push(9);
	
	cout<<q.size()<<endl;
	cout<<q.empty()<<endl;
	cout<<q.front()<<endl;
	cout<<q.back()<<endl;
	
	while(q.empty() != true)
	{
		cout<<q.front()<<" ";
		q.pop();
	}
	cout<<endl;
	
	return 0;
}
           

繼續閱讀