STL容器--queue

1概念

  • 先進先出
  • 不能進行遍歷
  • 不支持隨機存儲,只能從隊尾插入 對頭獲取元素
  • 沒有迭代器

2常用API

2.1構造函數

在這裏插入圖片描述

2.2stack數據存儲函數

在這裏插入圖片描述

2.3stack賦值操作函數在這裏插入圖片描述

2.4stack大小函數

在這裏插入圖片描述

3代碼

#include<iostream>
#include<queue>
using namespace std;
void test1(){
	queue<int> q;
	q.push(10);
	q.push(20);
	q.push(30);
	q.push(40);
	cout<<q.back()<<" ";
	//輸出
	while(q.size()>0){
		cout<<q.front()<<" ";
		q.pop();
	}
}
int main(){
	test1();
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章