![]() Enumerability and ownership of properties.Fails to enqueue because front = 0 & rear = SIZE - 1 * Function to display status of Circular Queue */įor (i = front i != rear i = (i + 1) % SIZE) } /* Q has only one element, so we reset the queue after deleting it. Print("After removing an element from the queue") # Your M圜ircularQueue object will be instantiated and called as such: Print("No element in the circular queue")įor i in range(self.head, self.tail + 1): # Delete an element from the circular queue If ((self.tail + 1) % self.k = self.head): # Insert an element into the circular queue # Circular Queue implementation in Python ![]() for the last element, reset the values of FRONT and REAR to -1.circularly increase the FRONT index by 1.add the new element in the position pointed to by REAR.if the rear reaches the end, next it would be at the start of the queue) circularly increase the REAR index by 1 (i.e.for the first element, set value of FRONT to 0.initially, set value of FRONT and REAR to -1.REAR track the last elements of the queue.FRONT track the first element of the queue.If REAR + 1 = 5 (overflow!), REAR = (REAR + 1)%5 = 0 (start of queue) Here, the circular increment is performed by modulo division with the queue size. when we try to increment the pointer and we reach the end of the queue, we start from the beginning of the queue. This reduces the actual size of the queue.Ĭircular Queue works by the process of circular increment i.e. Here, indexes 0 and 1 can only be used after resetting the queue (deletion of all elements). In a normal queue, after a bit of insertion and deletion, there will be non-usable empty space. The circular queue solves the major limitation of the normal queue. ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |