Queue is a linear datatype which operates First In First Out(FIFO) or Last In First Out (LIFO) operation
It is named as queue because it behaves as a real world queue
Example
- A line of car in a single lane
- Queue of people waiting at a food court
Queue is an abstract datatype with a bounded (predefined) capacity.It stores the elements of a limited size
It is a simple data structure that allows adding and removing elements in a particular order.The order is LIFO or FIFO
Working of Queue
- Queue is a linear data structure which operates FIFO or LIFO
- Elements are added at one end (rear end/back end) is called Enqueue
- Elements are removed from another end(front end/head end) is called Dequeue
Standard Queue Operations
- enqueue( )- Elements are added from one end
- dequeue( )- Elements are removed from another end
- isFull( )- Check if queue is full or not
- isEmpty( )- Check if queue is empty or not
- count( )- Get count of totoal items in the queue
Operations on Queue Interface
1)Adding the elements
Syntax
Example
Output
PriorityQueue:[2,4]
Updated PriorityQueue:[1,4,2]
2)Removing the elements
Example
Output
Initial Queue [Fuels, Purpose, Passion]
Result[Passion, Purpose]
3)Iterating the queue
Example
Output
Iterator:1, 4, 2,
Types of Queues
- Simple Queue -In Linear Queue, an insertion takes place from one end while the deletion occurs from another end
- 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
- Priority Queue -It is a special type of queue in which the elements are arranged based on the priority
- Double Ended Queue -In Deque or Double Ended Queue, insertion and deletion can be done from both ends of the queue either from the front or rear
Application
- Queue are used to maintain the play list in media players in order to add and remove the songs from the play-list
- Queues are widely used as waiting lists for a single shared resource like printer, disk, CPU