![]() |
VOOZH | about |
The queue is a linear data structure that follows the FIFO rule (first in first out). We can implement Queue for not only Integers but also Strings, Float, or Characters. There are 5 primary operations in Queue:
Note: Time complexity is of order 1 for all operations
Implementation:
Example
q1 after enqueue of 3 elements: 5->10->20 q1 after dequeue : 10->20 q2 after enqueue of 3 elements: hello->world->GFG q2 front = GFG, q2 rear = hello Created new Float type queue q3... Checking if queue is empty or not : true
Time Complexity: O(n) for traversing and rest O(1) for rest other operations
Auxiliary Space: O(1)