C++常用STL容器

发布时间 2023-12-16 22:47:10作者: walkallday

1.queue

#include<queue>
using namespace std;
queue<int> q;

常用方法

1.size()

q.size()

值为所包含的元素的个数

2.front()

q.front()

头元素

3.back()

q.back()

尾元素

4.push()

q.push(value)

value加入队列q

5.pop()

q.pop()

将头元素弹出队列q

测试代码:
#include<iostream>
#include<queue>
using namespace std;
int main()
{
    queue<int> q;
    for(int i=1;i<=4;i++) q.push(i*i);
    while(q.size())
    {
        cout<<q.front()<<" ";
        q.pop();
    }
    return 0;
}

1 4 9 16

2.vector