Containers queue
作者:
xianhai
,
2021-11-22 14:44:34
,
所有人可见
,
阅读 236
// constructing queues
#include <iostream> // std::cout
#include <deque> // std::deque
#include <list> // std::list
#include <queue> // std::queue
int main ()
{
std::deque<int> mydeck (3,100); // deque with 3 elements
std::list<int> mylist (2,200); // list with 2 elements
std::queue<int> first; // empty queue
std::queue<int> second (mydeck); // queue initialized to copy of deque
std::queue<int,std::list<int> > third; // empty queue with list as underlying container
std::queue<int,std::list<int> > fourth (mylist);
std::cout << "size of first: " << first.size() << '\n';
std::cout << "size of second: " << second.size() << '\n';
std::cout << "size of third: " << third.size() << '\n';
std::cout << "size of fourth: " << fourth.size() << '\n';
// 队列遍历
int myqueue_size = second.size();
for(int i = 0; i < myqueue_size; i++) { // myqueue_size 必须是固定值
std::cout << second.front() << std::endl;
second.push(second.front());
second.pop();
}
return 0;
}
http://www.cplusplus.com/reference/queue/priority_queue/
http://cpp.sh/