C STL之queue常見用法

2021-08-05 23:31:18 字數 424 閱讀 1722

queue 模板類的定義在標頭檔案中。

queue 佇列,先進先出,先入隊的先出隊。

宣告,queue《變數型別》 變數名。

入隊,q.push(x); 將x接到佇列的末端。

出隊,q.pop(); 彈出佇列的第乙個元素,不會返回被彈出元素的值。

訪問隊首元素,q.front(),即最早被壓入佇列的元素。

訪問隊尾元素,q.back(),即最後被壓入佇列的元素。

判斷佇列空,q.empty(),當佇列空時,返回true。

獲得元素個數,q.size()。

#include 

#include

using

namespace

std;

int main()

C STL之vector常見用法

vector 底層資料結構為陣列 支援快速隨機訪問 include include include using namespace std 比較函式 bool cmp int a,int b cout cout v1.push back 100 在末尾插入元素 v1.insert v1.begin ...

queue的常見用法

queue是一種先入先出的容器 include include using namespace std queueq stl只能通過front 訪問隊首元素,或者使用back 訪問隊尾元素 queueq for int i 0 i 5 i cout 獲取容器隊首和隊尾元素 queueq for in...

queue的常見用法詳解

queue翻譯為佇列,是乙個先進先出的容器,要使用queue,應先新增標頭檔案 include,並在標頭檔案下面加上 using namespace std 定義的寫法和其他stl容器相同,typename可以是任意基本資料型別或容器 queuename 由於佇列 queue 本身就是一種先進先出的...