queue::queue
建構是空的或為基礎容器物件複本的佇列。
queue( );
explicit queue(
const container_type& _Right
);
參數
- _Right
建構的佇列是複製的 const 容器。
備註
佇列的預設基底容器是雙向佇列。 您也可以指定清單為基礎容器,不過,您無法指定向量,,因為它缺少必要的 pop_front 成員函式。
範例
// queue_queue.cpp
// compile with: /EHsc
#include <queue>
#include <vector>
#include <list>
#include <iostream>
int main( )
{
using namespace std;
// Declares queue with default deque base container
queue <char> q1;
// Explicitly declares a queue with deque base container
queue <char, deque<char> > q2;
// These lines don't cause an error, even though they
// declares a queue with a vector base container
queue <int, vector<int> > q3;
q3.push( 10 );
// but the following would cause an error because vector has
// no pop_front member function
// q3.pop( );
// Declares a queue with list base container
queue <int, list<int> > q4;
// The second member function copies elements from a container
list<int> li1;
li1.push_back( 1 );
li1.push_back( 2 );
queue <int, list<int> > q5( li1 );
cout << "The element at the front of queue q5 is "
<< q5.front( ) << "." << endl;
cout << "The element at the back of queue q5 is "
<< q5.back( ) << "." << endl;
}
需求
標題: <佇列>
命名空間: std