queue


A queue is an adapter that can use any container supporting push_back() and pop_front() as a first-in, first-out data structure. Following is an overview of queue .

Iterator Type

Because adapters do not support iteration, a queue has no associated iterator.

Implementation

A queue is implemented as a class comprised of inline functions converting push() and pop() messages into push_back() and pop_front() messages. The only STL containers that support these functions are list and deque . Of these two containers, deque yields a better performance.

Common Uses

A queue is useful for implementing strictly first-in, first-out data structures when direct indexed access to the items should not be performed.

Interface

A queue does not introduce any new functions, but an additional parameter is required if you are using an older compiler and its implementation of pop() operates differently from that of stack .

The following example illustrates the first-in, first-out nature of a queue .

Example <ospace/osstd/examples/queue1.cpp>
#include <iostream>
#include <list>
#include <queue>

void
main()
  {
  queue< int, list< int > > q;
  q.push( 42 );
  q.push( 101 );
  q.push( 69 );
  while ( !q.empty() )
    {
    cout << q.front() << "\n";
    q.pop();
    }
  }

42
101
69


 
 

Copyright©1994-2026 Recursion Software LLC
All Rights Reserved - For use by licensed users only.