Introduction:
- Like stacks, queues are also lists.
- In queue insertion is done at one end(Rear) and deletion is done at the other end(Front).
- The removal of elements from a queue is possible in the same order in which the insertion of elements is made in to the queue.
- Since it is always the first item to be put in to the queue that is the first item to be removed a queue is a First In First Out(FIFO) data structure
A B C D E F
| |
Front Rear
- Queues are used in network programming,operating systems and other situations in which many different processes must share resources such as CPU time.
Basic Queue Operation:
- Elements can only be added to the rear of the queue and removed from the front of the queue.
- Insertion of an element in to a queue is known as enqueue and removing an element from the queue is known as dequeue.
1. Insertion operation in a queue(enqueue)
- Inserts an element at the end of the queue.
- When a new element is added to the queue the rear pointer is incremented
2. Deletion operation in a queue(dequeue)
- removes and returns the element at the front of the queue.
- When a dequeue operation is performed the element pointed by the front pointer is removed and the front pointer is incremented.
Applications of Queue:
- Waiting Lists
- Access to shared resources (eg,Printer)
- Multiprogramming
- Round Robin Scheduling