欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Queue 队列 课程回顾

程序员文章站 2022-04-08 14:56:30
...

2020.7.22

Queue

#include <iostream>
#include <queue>
using namespace std;
int main ()
{
    queue <int> q;
    q.push(1);
    q.pop();
    q.front();
    q.back();
    q.size();
    q.empty();
    
    deque<int> dp;
    dp.push_back(1);
    dp.push_front(1);
    dp.front();
    dp.back();
    dp.size();
    dp.empty();
    
    priority_queue<int> pq;
    pq.push(1);
    pq.pop();
    pq.top();
    pq.size();
    pq.empty();
}

Queue - 队列

Queue 队列 课程回顾
队列是FIFO (First In First Out)
栈是LIFO (Last In First Out) 栈的具体细节不妨看看这个啊~
命名方式也是和栈一样的

基本语句

empty
Test whether container is empty (public member function )
size
Return size (public member function )
front
Access next element (public member function )
back
Access last element (public member function )
push
Insert element (public member function )
emplace
Construct and insert element (public member function )
pop
Remove next element (public member function )
swap
Swap contents (public member function )


Deque - 双端队列

双端队列的意思就是元素可以从队列的两头push or pop

基本语句

push_back
Add element at the end (public member function )
push_front
Insert element at beginning (public member function )
pop_back
Delete last element (public member function )
pop_front
Delete first element (public member function )
insert
Insert elements (public member function )
erase
Erase elements (public member function )
swap
Swap content (public member function )
clear
Clear content (public member function )
emplace
Construct and insert element (public member function )
emplace_front
Construct and insert element at beginning (public member function )
emplace_back
Construct and insert element at the end (public member function )


Priority_queue - 优先队列

其实这就是一个 FILO (First In Last Out) 的队列

基本语句

empty
Test whether container is empty (public member function )
size
Return size (public member function )
top
Access top element (public member function )
push
Insert element (public member function )
emplace
Construct and insert element (public member function )
pop
Remove top element (public member function )
swap
Swap contents (public member function )

相关标签: 课程回顾