codeintuition-logo

Accessing the back of the queue


The back operation returns the value stored at the back of the queue. In the linked list implementation of a queue, the back of the queue is the tail node of the linked list. We have two cases to consider here.

1. Queue is empty

We can return -1 to indicate that there are no items in the queue. Ideally, we should be throwing an error, but for the sake of simplicity here, we return -1

Liking the course? Check our discounted plans to continue learning.