Queue

17.1 - Queue basic 1


Imagine that you are a British person waiting in a queue at a bus stop after a nice cup of tea with biscuits. The first person to arrive at the bus stop will be the first to enter the bus. Therefore this phenomenon can be described by the queue container, since it is a FIFO (First In First Out) container.

Queue has these operations:

  • push, which inserts an element at the end.
  • pop, which removes the first element.
  • front, which returns the first element.
  • back, which returns the last element.
  • empty, which returns whether the queue is empty or not.
  • size, which returns the number of elements stored in the queue.

To use the queue implemented in the C++ standard library, include the header.

Your task is to create an interactive program using an integer queue which accepts the following commands:

  • push
    Push the number into the queue.
  • pop
    Remove the first number.
  • front
    Print the first number.
  • back
    Print the last number.
  • empty
    Print true or false whether the queue is empty or not.
  • size
    Print the size of the queue.

Sample input

push 10
push 20
push 30
size
front
back
empty

Sample output

3
10
30
false
#include <queue> #include <iostream> int main() { }