Isempty() − Checks if the queue is empty. Peek() − Gets the element at the front of the queue without removing it. Here we shall try to understand the basic operations associated with queues −Įnqueue() − add (store) an item to the queue.ĭequeue() − remove (access) an item from the queue.įew more functions are required to make the above-mentioned queue operation efficient. Queue operations may involve initializing or defining the queue, utilizing it, and then completely erasing it from the memory. For the sake of simplicity, we shall implement queues using one-dimensional array. The following diagram given below tries to explain queue representation as data structure −Īs in stacks, a queue can also be implemented using Arrays, Linked-lists, Pointers and Structures. Queue RepresentationĪs we now understand that in queue, we access both ends for different reasons. More real-world examples can be seen as queues at the ticket windows and bus-stops. Queue follows First-In-First-Out methodology, i.e., the data item stored first will be accessed first.Ī real-world example of queue can be a single-lane one-way road, where the vehicle enters first, exits first. One end is always used to insert data (enqueue) and the other is used to remove data (dequeue). Unlike stacks, a queue is open at both its ends. Queue is an abstract data structure, somewhat similar to Stacks.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |