17-2. Queues

A queue represents a data structure adhering to the First In First Out (FIFO) principle. A queue represents a waiting list. It can be seen as a specialized form of list where elements are inserted at the end (tail) of the queue and accessed and removed from the beginning (head) of the queue.

  • How it works?

Enqueue elements to a queue:

 

When an element (1) arrives at the queue, it is placed at the end. Subsequently, when a new element (2) arrives, it is placed after the element (1). Following this, when a new element (3) arrives, it is placed after the element (2).

           

Dequeue elements to a queue:

When an element is removed from a queue, the first element (1) is extracted from the queue. Subsequently, the next element (2) is removed, followed by the removal of the element (3).

 

  • Basic operations of a queue
    • Enqueue: Add an element to the end of the queue
    • Dequeue: Remove an element from the front of the queue
    • IsEmpty: Check if the queue is empty
    • getSize: Return the size of the stack

 

  • Queue Implementation

Test Program:

Output:

0 1 2 3 4 5 6 7 8 9