Accessing the front of the queue
The front operation returns the value stored at the front of the queue. In the linked list implementation of a queue, the front of the queue is the head 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.