0% found this document useful (0 votes)
2 views4 pages

Queue Using Array

A Queue is a linear data structure that operates on a FIFO basis, where the first element added is the first to be removed. Key operations include ENQUEUE for adding elements, DEQUEUE for removing them, and functions to check if the queue is empty or full. Queues are widely used in various applications such as scheduling, buffering, and managing shared resources.

Uploaded by

rehna
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views4 pages

Queue Using Array

A Queue is a linear data structure that operates on a FIFO basis, where the first element added is the first to be removed. Key operations include ENQUEUE for adding elements, DEQUEUE for removing them, and functions to check if the queue is empty or full. Queues are widely used in various applications such as scheduling, buffering, and managing shared resources.

Uploaded by

rehna
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Queue

A Queue is a linear data structure that follows the FIFO (First In First Out)
principle.
The element inserted first is removed first.

Example:
People standing in a line at a ticket counter.

Basic Terms
• Front – Points to the first element of the queue
• Rear – Points to the last element of the queue

Operations on Queue

[Link] (Insertion)

Adds an element at the rear end of the queue.


Condition: Queue should not be full.

If rear == MAX − 1
Print “Queue Overflow” and Stop
If front == −1
Set front = 0
Set rear = rear + 1
Insert item into queue[rear]
[Link] (Deletion)

Removes an element from the front end of the queue.


Condition: Queue should not be empty.

If front == −1 OR front > rear


Print “Queue Underflow” and Stop
Store queue[front] in item
Set front = front + 1
If front > rear
Set front = rear = −1
3. Peek / Front Element
• Returns the element at the front without removing it.

If front == −1 OR front > rear


Print “Queue is Empty” and Stop
Return queue[front]

4. isEmpty
• Checks whether the queue is empty.
If front == −1 OR front > rear
Return TRUE
Else
Return FALSE

5. isFull
• Checks whether the queue is full.

If rear == MAX − 1
Return TRUE
Else
Return FALSE

Advantages
• Simple structure
• Efficient insertion and deletion
• Useful in scheduling and buffering
• Queues are useful when a particular service is used by multiple
consumers.
• Queues are fast in speed for data inter-process communication.

Disadvantages
• Wastage of memory in array implementation
• Fixed size (cannot grow dynamically)

Applications of Queue
• Shared Resource: Queues are widely used as waiting lists for a
single shared resource like printer, disk, CPU.
• Network: 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.
• Queues are used as buffers in most of the applications like MP3
media player, CD player, etc.
• Queue are used to maintain the play list in media players in order
to add and remove the songs from the play-list.
• Interrupt Handling: Queues are used in operating systems for
handling interrupts.
• Used in Breadth First Search (BFS)
• Ticket reservation systems

You might also like