Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) std::queue

 

std::queue is an STL container for FIFO ('First In, First Out') storage of elements.

 

#include <cassert>
#include <queue>

int main()
{
  //Create the FIFO container std::queue
  std::queue<int> d;

  //Push elements at the back
  d.push(1);
  d.push(2);
  d.push(3);

  //Can only access first and last element
  assert(d.front() == 1);
  assert(d.back() == 3);

  //Pop out first element in line
  d.pop();

  //Access the new first and last element
  assert(d.front() == 2);
  assert(d.back() == 3);

  //Pop out the next first element in line
  d.pop();

  //Access the new first and last element
  assert(d.front() == 3);
  assert(d.back() == 3);
}

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict