Professional Documents
Culture Documents
Queue
Queue
QUEUE
Queue is an abstract (LINEAR) data structure
A queue is open at both its ends. One end is always used to insert data (enqueue)
and the other is used to remove data (dequeue).
Element is inserted from one end called the REAR(also called tail), and the removal
of existing element takes place from the other end called as FRONT(also called
head).
Queue follows First-In-First-Out methodology, i.e., the data item stored first will be
accessed first.
Basic features of Queue
1.Like stack, queue is also an ordered list of elements of similar data types.
2.Queue is a FIFO( First in First Out ) structure.
3.Once a new element is inserted into the Queue, all the elements inserted
before the new element in the queue must be removed, to remove the new
element.
4.peek( ) function is oftenly used to return the value of first element
without dequeuing it.
Basic Operations of Queue
Case 3:
F=1 N=5 R=4
F R N
Case 1: A B c d
1. New data is always added to the location pointed by the tail pointer, and once the data is added, tail
pointer is incremented to point to the next available location.
In a circular queue, data is not actually removed from the queue. Only the head pointer is incremented by one
position when dequeue is executed. As the queue data is only the data between head and tail, hence the data
left outside is not a part of the queue anymore, hence removed.
•Also, the head and the tail pointers can cross each other. In other words, head
pointer can be greater than the tail. Sounds odd? This will happen when we
dequeue the queue a couple of times and the tail pointer gets reinitialised upon
reaching the end of the queue.
•The head and the tail pointer will get reinitialised to 0 every time they reach the end of the queue.
Applications of Circular Queue
• CPU scheduling
• Memory management
• Traffic Management