queue库中函数的浅谈

来源:互联网 发布:淘宝网非主流女装 编辑:程序博客网 时间:2024/05/16 15:45

队列是一种数据结构。特点是先入先出(FIFO)
1.队列的声明

#include<iostream>#include<dueue>using namespace std;int main(void){    deque<int> mydeck (3,100);        // deque with 3 elements    list<int> mylist (2,200);         // list with 2 elements    queue<int> first;                 // empty queue    queue<int> second (mydeck);       // queue initialized to copy of deque    queue<int,list<int> > third; // empty queue with list as underlying container    queue<int,list<int> > fourth (mylist);    cout << "size of first: " << first.size() << '\b';    cout << "size of second: " << second.size() << '\b';    cout << "size of third: " << third.size() << '\b';    cout << "size of fourth: " << fourth.size() << '\b';    return 0;}

则结果依次为:0 3 0 2

#include<iostream>#include<queue>using namespace std;int main(void){    queue<int> c;    //以下代码c表示该队列,并插入到该行    return 0;}

2.bool empty() const : 判断队列是否为空

c.empty();

3.size_type size() const: 返回队列中元素个数

c.size()

4.value_type& front();

const value_type& front() const;

返回队列中第一个元素,即最后插入到队列中的那个元素

c.front();

5.value_type& back();

const value_type& back() const;

返回队列中最后一个元素,即最先入队的那个元素

c.back();

6.void push (const value_type& val)

插入一个新元素在队尾

c.push(value)

7.void emplace(Args&& args)

插入一个新的元素在队尾

c.emplace(args);

8.void pop()

移除队首元素

c.pop();

9.void swap(queue& x)

交换两个队列的内容

c.swap(d);

10.与stack和vector一样,重载了几个运算符:
== != < <= > >=

原创粉丝点击