Linear Queue Implementation

Similar to Stack, Queue is a linear data structure that follows a particular order in which the operations are performed for storing data. The order is First In First Out (FIFO). One can imagine a queue as a line of people waiting to receive something in sequential order which starts from the beginning of the line. It is an ordered list in which insertions are done at one end which is known as the rear and deletions are done from the other end known as the front. A good example of a queue is any queue of consumers for a resource where the consumer that came first is served first.

The difference between stacks and queues is in removing. In a stack we remove the item the most recently added; in a queue, we remove the item the least recently added.

It has three components:

  1. A Container of items that contains elements of queue.
  2. A pointer front that points the first item of the queue.
  3. A pointer rear that points the last item of the queue.

Operations associated with a queue in C :

Algorithm

Queue follows the First-In-First-Out pattern. The first element is the first to be pulled out from the list of elements.


Queues in C can be implemented using Arrays, Lists, Structures, etc. Below here we have implemented queues using Arrays in C.

Program using C