- Queue is a data structure that supports FIFO (First In First Out) or FCFS (First Come First Serve).
- It is a linear data structure.
- Example: Queue of people standing outside ATM.
- enqueue(): This operation will help us to add a new element in the queue.
- dequeue(): This operation will help us to remove a new element in the queue.
- isFull(): This operation will help us know if a queue is full or not.
- isEmpty(): This operation will help us know if a queue is empty or not.
- front(): This operation will give us the element which came first.
- size(): This operation will give us the size of the queue.
front: tracks the first element; back/rear: element gets added from the end
- Simple Queue: Element is added from the back and removed from front.
- Priority Queue: Based on custom priority, element is at the front.
- Circular Queue: Front and rear are connected.
- Double Ended Queue/Deque: Addition and removal of elements can be done from both sides.
- By using Array
- By using Linked List
- Array can manage data easily.
- It is not space efficient.
- In normal queues, back is responsible for addition of elements and front is responsible for accessing front element as well as removal of element.
- Deque stands for Double Ended Queue.
- We can add/remove elements from both front and back sides.
- It is used to implement stack (by default).