Queue
Creating a queue:
will create a queue that stores elements of type <return_type>
. The queue follows the First In, First Out (FIFO) principle, meaning the first element added is the first one to be removed.
Functions:
Function
Description
O notation
enqueue(x)
Adds the element x of type <return_type>
to the queue at the end.
O(1)
dequeue()
Removes the firstly added element to the queue (if any) and returns it.
O(1)
enqueueFront(x)
Adds the element x of type <return_type>
to the queue at the beginning.
O(1)
dequeueBack()
Removes the lastly added element to the queue (if any) and returns it.
O(1)
empty()
Check whether the queue is empty, returns a boolean.
O(1)
getFront()
Returns the element that's first in queue (if any).
O(1)
getBack()
Returns the element that's last in queue (if any).
O(1)
Example use case:
Last updated