Queue: Introduction And Application

Link Copied To Clipboard !

Data Structures

A Queue is a linear, ordered collection of items or data structure in which the operations are performed in First In First Out fashion . Meaning, it is always the first item to be put into the queue, and first item is to be removed first .

The main difference between stack and queue is in removing items. In stack, we remove the most recently added but in case of queue, we remove the least recently added .

A good example of queue is any queue of people waiting for resources, i.e. The first person in the queue is served first.

Queue As ADT(Abstract Data Type)

A Queue contains elements of same type arranged in sequential order. Operations takes place at both ends, insertion is done at end and deletion is done at front. Following operations can be performed:
enqueue() – Inserts an element at the end of the queue.
dequeue() – Removes and returns the first element of queue, if the queue is not empty.
front() – Returns the front element of the queue without removing it, if the queue is not empty.

back() – Returns the element at the back of queue without removing it, if the queue is not empty.
size() – Returns the number of elements in the queue.
empty() – Returns true if the queue is empty, otherwise returns false.
full() – Returns true if the queue is full, otherwise returns false.

Applications Of Queue Data Structure

  1. Access to shared resources : With in a computer system, there may be queues of tasks waiting for the pointer in order to access to disk storage or even in a time-sharing system.
  2. Task Scheduling in operating system.
  3. Queue can be used as an auxiliary data structure for implementing algorithms.
  4. Queue can be used as a component of other data structure.

You May Also Like