![]() ![]() If(front=-1 & rear=-1) // condition to check queue is emptyĮlse if((rear+1)%max=front) // condition to check queue is full function to insert an element in a circular queue Implementation of circular queue using Array Let's understand the enqueue and dequeue operation through the diagrammatic representation. If there is only one element left which is to be deleted, then the front and rear are reset to -1.Īlgorithm to delete an element from the circular queue.When the element is deleted, the value of front gets decremented by 1.If the queue is empty, we cannot perform the dequeue operation. First, we check whether the Queue is empty or not.The steps of dequeue operation are given below: When front =0 & rear = max-1, which means that front is at the first position of the Queue and rear is at the last position of the Queue.Īlgorithm to insert an element in a circular queue.There are two cases in which the element cannot be inserted: If front != 0 and rear = max - 1, it means that queue is not full, then set the value of rear to 0 and insert the new element there.If rear != max - 1, then rear will be incremented to mod(maxsize) and the new value will be inserted at the rear end of the queue.There are two scenarios in which queue is not full: When we insert a new element, the rear gets incremented, i.e., rear=rear+1.When we insert the first element in a Queue, front and rear both are set to 0. Initially the front and rear are set to -1.First, we will check whether the Queue is full or not.The steps of enqueue operation are given below: After green light, the red light gets ON. Like red light gets ON for one minute then yellow light for one minute and then green light. Each light of traffic light gets ON one by one after every jinterval of time. Traffic system: In a computer-control traffic system, traffic light is one of the best examples of the circular queue. ![]() CPU Scheduling: The operating system also uses the circular queue to insert the processes and then execute them.But in case of a circular queue, the memory is managed efficiently by placing the elements in a location which is unused. As we have already seen that in linear queue, the memory is not managed very efficiently. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |