queue::queue |
public member function |
explicit queue ( const Container& ctnr = Container() ); |
|
Construct queue
Constructs a queue container adaptor object.
A container adaptor keeps a container object as data. This container object is a copy of the argument passed to the constructor, if any, otherwise it is an empty container.
Parameters
- ctnr
- Container object
Container is the second class template parameter (the type of the underlying container for the queue; by default: deque<T>, see class description).
Example
// constructing queues
#include <iostream>
#include <deque>
#include <list>
#include <queue>
using namespace std;
int main ()
{
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: " << (int) first.size() << endl;
cout << "size of second: " << (int) second.size() << endl;
cout << "size of third: " << (int) third.size() << endl;
cout << "size of fourth: " << (int) fourth.size() << endl;
return 0;
}
|
Output:
size of first: 0 size of second: 3 size of third: 0 size of fourth: 2
|
Complexity
Constant (one container construction). Although notice that the container construction itself may not take constant time.