A Queue is data structure in which insertion is done at the end and deletion is done from the front of the queue. Queue is called First in first out (FIFO) data structure. Whenever an element is added to the queue, the value of REAR is increased by 1. Whenever an element is deleted from the queue, the value of FRONT is increased by 1. The elements are deleted from the queue from the end and front. The elements are inserted in the queue from the end called rear. Queue is useful in the single processor system where only one user at a time can be serviced.
The queue can be implemented in two ways-Queue as an array called static queue and queue as a linked list called dynamic queue. An array is a static data structure. Therefore, by using an array, a queue of fixed size is implemented. The linked list implementation of a queue is done by linking the nodes together to form a chain.
If the first element is added to the queue, then both front and rear are increased by 1. Otherwise for every new insertion of element, only the value of rear is increased by 1. Whenever an item is deleted from the queue, the value of the front is increased by 1.
Initially, the values of front and rear are initialize with -1 because the first element is stored in the array at the zero index.