Chapter 5 Queue
Chapter 5 Queue
Queue
1. A queue can be defined as an ordered list which enables insert operations
to be performed at one end called REAR and delete operations to be
performed at another end called FRONT.
3. For example, people waiting in line for a rail ticket form a queue.
Applications of Queue
1. Queues are widely used as waiting lists for a single shared resource like
printer, disk, CPU.
2. Queues are used in asynchronous transfer of data (where data is not
being transferred at the same rate between two processes) for eg.
pipes, file IO, sockets.
3. Queues are used as buffers in most of the applications like MP3 media
player, CD player, etc.
4. Queue are used to maintain the play list in media players in order to
add and remove the songs from the play-list.
5. Queues are used in operating systems for handling interrupts.
Types of Queue
There are four different types of queue that are listed as follows -
o Simple Queue or Linear Queue
o Circular Queue
o Priority Queue
o Double Ended Queue (or Deque)
Circular Queue
In Circular Queue, all the nodes are represented as circular. It is similar to the
linear Queue except that the last element of the queue is connected to the
first element. It is also known as Ring Buffer, as all the ends are connected to
another end. The representation of circular queue is shown in the below
image -
The drawback that occurs in a linear queue is overcome by using the circular
queue. If the empty space is available in a circular queue, the new element can be
added in an empty space by simply incrementing the value of rear. The main
advantage of using the circular queue is better memory utilization.
Priority Queue
It is a special type of queue in which the elements are arranged based on the
priority. It is a special type of queue data structure in which every element has a
associated with it. Suppose priority some elements occur with the same priority,
they will be arranged according to the FIFO principle. The representation of priority
queue is shown in the below image –
insertion in priority queue takes place based on the arrival, while deletion in the
priority queue occurs based on the priority. Priority queue is mainly used to
implement the CPU scheduling algorithms.
Write OVERFLOW
Go to step
[END OF IF]
ELSE
Step 4: EXIT
OthStep 2: EXIT
int delete (int queue[], int max,erwise, keep increasing the value of front and return the
item stored at the front end of the queue at each time.
Algorithm
Step 1: IF FRONT = -1 or FRONT > REAR
Write UNDERFLOW
ELSE
SET VAL = QUEUE[FRONT]
Step 2 :I if front=rear
front=-1
rear =-1
else
SET FRONT = FRONT + 1
[END OF IF]
Step 3: Exit