Deque is a special queue where both primary operations (enqueue and dequeue) can be done from both the front and rear end. So, we can imagine it as a queue with additional APIs. The code looks similar to other queues with two additional operations. The upcoming section will discuss these additional operations.
Understanding deque – double-ended queue
Primary operations – deque
Instead of enqueue and dequeue, the APIs here are enqueueFront, enqueueRear, dequeueFront, and dequeueRear. In a usual queue, the enqueue operation happens at the rear end, so there is no need to discuss the enqueueRear API here. Similarly, the dequeueFront API is not discussed here.
The other two APIs look like the following:
fun enqueueFront...