Queue

Queue is a first-in-first-out (FIFO) data structure. It supports three operations:

  • Push: push an element to the end of the queue
  • Pop: pop an element from the front of the queue
  • Front: get the frontmost element of the queue

The queue is available in C++ STL:

// #include <queue>

queue<int> q;
q.push(3);  // q: 3
q.push(4);  // q: 3 4
q.push(5);  // q: 3 4 5
cout << q.front() << "\n";  // 3
q.pop();    // q: 4 5
cout << q.front() << "\n";  // 4

Authored by s16f22