12/23/2023 0 Comments Array enqueue dequeue java![]() ![]() We can easily check if a queue is empty or not by checking if head and tail are pointing to the same location or not at any time. Initially, the queue will be empty i.e., both head and tail will point to the same location i.e., at index 1. In this case, our tail will point to the first element of the array and will follow a circular order. Suppose tail is at the last element of the queue and there are empty blocks before head as shown in the picture given below. To insert any element, we add that element at tail and increase the tail by one to point to the next element of the array. head will always point to the oldest element which was added and tail will point where the new element is going to be added. ![]() We will maintain two pointers - tail and head to represent a queue. Customers calling a call center are kept in queues when they wait for someone to pick up the calls. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |