Queue is data structure like array and stack. But here the first element added to the queue, will be the first element removed from the queue. So queue called first in first out (FIFO) or first come first serve
Enqueue(Key): To add key to collection
Key Dequeue(): To remove and return least recently-added key
Boolean Empty(): means,, Are there any elements?
We can implement queue in several way (Linked list, Array, 2 Stack).
The first : When we enqueue, we are going to push to the back of the linked list
The second : To make sure the the queue list is empty , we make sure if the head is null or not
It’s easy to implement queue using array but pay attention in this case.
This case occurred when we have array say with size (5) but this array have (4) occupied by values
- And it would be hard to distinguish read and write index 2 because the queue is full
- Or read and write index both 2 because the queue is empty
- So we have a buffer of at least one that can’t be written to make sure read and write are separate and and distinct if the queue isn’t empty
one distinction between the array and linked list implementation
is that in the array implementation we have a maximum size that the queue can grow to so it is bounded