What is Queue in Data Structure ?
-
- A queue is a container of objects (a linear collection) that are inserted and removed according to the first-in first-out (FIFO) principle.
- Here the first element is inserted from one end called REAR and deleted from the other end called as FRONT.
- Front points to the beginning of the queue and Rear points to the end of the queue.
Operations on Queue
Operation | Description |
---|---|
enqueue() | This function defines the operation for adding an element into queue. |
dequeue() | This function defines the operation for removing an element from queue. |
init() | This function is used for initializing the queue. |
Front | Front is used to get the front data item from a queue. |
Rear | Rear is used to get the last item from a queue. |
Queue Implementation
- Array is the easiest way to implement a queue. Queue can be also implemented using Linked List or Stack.
- Front and Rear of the queue point at the first index of the array. (Array index starts from 0).
- While adding an element into the queue, the Rear keeps on moving ahead and always points to the position where the next element will be inserted. Front remains at the first index.