The isFull operation is used to check if the queue is full or not. The Peek operation is used to return the front most element of the queue. Set front and rear as -1 for the last element.The Dequeue operation is used to remove an element from the rear of the queue. Set the front as 0 for the first element. The Enqueue operation is used to add an element to the front of the queue. We can use queue to perform its main two operations: Enqueue and Dequeue, other operations being Peek, isEmpty and isFull. For the sake of simplicity, we will be implementing queue using a one-dimensional array. The following diagram tries to explain the queue representation as a data structure-Ī Queue in data structure can be implemented using arrays, linked lists, or vectors. Queue RepresentationĪ Queue in data structure can be accessed from both of its sides (at the front for deletion and back for insertion). In the above illustration, we can see that the person standing at the front of the queue will be the first one to leave the queue and the person standing at the last of the queue will be the last one to leave. A Queue is a sequential data type, unlike an array, in an array, we can access any of its elements using indexing, but we can only access the element at the front of the queue at a time.Ī queue of people waiting for their turn or a queue of airplanes waiting for landing instructions are also some real life examples of the queue data structure. It is a FIFO (First In First Out) data structure, which means that we can insert an item to the rear end of the queue and remove from the front of the queue only. The Queue in data structure is an ordered, linear sequence of items. The front of the queue is returned using the peek operation. Insertion happens at the rear end of the queue whereas deletion happens at the front end of the queue. A Queue is an abstract linear data structure serving as a collection of elements that are inserted (enqueue operation) and removed (dequeue operation) according to the First in First Out (FIFO) approach.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |