Dequeue: It performs a deletion operation in the Queue.If queue is not empty and rear is equal to n-1, then rear is set to 0.If queue is not empty, then the value of the rear gets incremented.If the queue is empty, then the front and rear are set to 0 to insert a new element.The given below are the scenarios that can be considered while inserting an element: Enqueue: It inserts an element in a queue. The following are the two operations that can be performed on a circular queue are: If either of the above conditions is satisfied means that the queue is a circular queue. The problem of managing the circular queue is overcome if the first position of the queue comes after the last position of the queue.Ĭonditions for the queue to be a circular queue It helps in refilling all the free spaces. In the circular queue, when the rear reaches the end of the queue, then rear is reset to zero. If we want to insert new elements at the beginning of the queue, we can insert it using the circular queue data structure. The problem that arises with the linear queue is that if some empty cells occur at the beginning of the queue then we cannot insert new element at the empty space as the rear cannot be further incremented.Ī circular queue is also a linear data structure like a normal queue that follows the FIFO principle but it does not end the queue it connects the last position of the queue to the first position of the queue. Dequeue: The dequeue operation is used to delete the existing element from the front end of the queue.Īs we know that in a queue, the front pointer points to the first element while the rear pointer points to the last element of the queue.Enqueue: The enqueue operation inserts the new element from the rear end.There are two operations that can be performed on a linear queue: It has two pointers, i.e., front and rear, where the insertion takes place from the front end, and deletion occurs from the front end. It consists of data elements which are connected in a linear fashion. Next → ← prev Linear vs Circular Queue What is a Linear Queue?Ī linear queue is a linear data structure that serves the request first, which has been arrived first.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |