Accessing the back of the queue
This back operation returns the value at the back of the queue. Since we always store the index of the data item at the back of the queue in the array implementation, we need to return the value at that index to the user. 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.