Types of Queues in Data Structure:
Queue in the data structure is of the following types
- Simple Queue
- Circular Queue
- Priority Queue
- Dequeue (Double Ended Queue)
Simple Queue
The simple queue is a normal queue where insertion takes place at the FRONT of the queue and deletion takes place at the END of the queue.
Circular Queue :
- In a circular queue, the last node is connected to the first node.
- A circular queue is also called as Ring Buffer.
- Insertion in a circular queue happens at the FRONT and deletion at the END of the queue.
Priority Queue :
- In a priority queue, the nodes will have some predefined priority.
- Insertion in a priority queue is performed in the order of arrival of the nodes.
- The node having the least priority will be the first to be removed from the priority queue.
Dequeue (Double Ended Queue) :
In a Double Ended Queue, insertion and deletion operations can be done at both FRONT and END of the queue.
Basic operations in a queue
The most basic queue operations in the data structure are the following
- enqueue() - Adds an element at the beginning of the queue. If the queue is full, then it is an overflow.
- dequeue() - Deletes an element at the end of the queue. If the queue is empty, then it is an underflow.
enqueue()
- Check if the queue is full.
- If the queue is full, then print "Queue overflow".
- Else increment REAR by 1.
- Assign QUEUE [ REAR ] = ELEMENT.
dequeue()
- Check if the queue is empty.
- If the queue is empty, the print "Queue underflow".
- Copy the element at the front of the queue to some temporary variable, TEMP = QUEUE[ FRONT ].
- Increment FRONT by 1.
- Print temp and delete it.
0 Comments
Doubts? Please let our team know So that we can serve you better.