Similar to insertion, deleting an element is only possible from the front of the queue. There is no interaction needed with the rest of the elements. Inserting an element is only possible at the rear. Similarly, searching an element will involve continuously shifting the front element off the queue until the required element is found. Queue Complexity AccessĪn arbitrary element in a queue can only be accessed by continuously shifting the front element. If there exist two elements with the same priority, then the order of which the element was inserted is considered. There can be different criteria’s for the priority queue to assign priorities.Īn element with the highest priority gets processed first. This priority determines which elements are to be deleted and processed first. Priority QueueĪ priority queue assigns a priority to each element in the queue. ![]() There is no shifting involved and the whole queue can be used for storing all the elements. This is an efficient implementation for a queue that has fixed maximum size. Circular Queue (Circular Buffer)Ī circular queue uses a single, fixed-size buffer as if it were connected end-to-end like a circle.Ĭburnett, derivative work: Pluke A double-ended queue allows for insertion and deletion from both ends. In a standard queue, insertion can only be done from the back and deletion only from the front. Printf("\nDeleted item is: %d", queue) Ī queue can have some variations which make it useful in certain situations: Double-Ended queue (Deque) Then check whether both front and rear are equal ( front = rear ), if it TRUE, then set both front and rear to ‘-1’ ( front = rear = -1).Then display the queue as the deleted element. If it is NOT EMPTY, then increment the front value by one ( front ).If it is EMPTY, then display an error and terminate the function.If it is NOT FULL, then increment the rear value by one ( rear ) and set queue = value.If it is FULL, then display an error and terminate the function. ![]()
3 Comments
|
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |