Breaking Posts

6/trending/recent

Hot Widget

Type Here to Get Search Results !

Queue

Queue Data Structures
  • A queue is an extended form or a linear data structure in which the initial element is added from one end, known as the REAR (sometimes known as the tail), and the last member is deleted from the other end, known as the FRONT (also called head). 
  • This turns the queue into a FIFO data structure, meaning that the member that was added first will likewise be removed first.
  • Enqueue is the process of adding an element to a queue, while Dequeue is the process of removing an element from a queue.

Basic features of Queue

  1. Like Stack, Queue is also an ordered list of elements of similar data types.
  2. Queue is a FIFO( First in First Out ) structure.
  3. Once a new element is inserted into the Queue, all the elements inserted before the new element in the queue must be removed, to remove the new element.
  4. peek( ) function is oftenly used to return the value of first element without dequeuing it.

Applications of Queue

Queue, as the name suggests is used whenever we need to have any group of objects in an order in which the first one coming in, also gets out first while the others wait for there turn, like in the following scenarios :
  1. Serving requests on a single shared resource, like a printer, CPU task scheduling etc.
  2. In real life, Call Center phone systems will use Queues, to hold people calling them in an order, until a service representative is free.
  3. Handling of interrupts in real-time systems. The interrupts are handled in the same order as they arrive, First come first served.

Implementation of Queue

  • An Array, Stack, or Linked List can be used to implement a Queue. Using an Array is the simplest approach to construct a queue. 
  • The queue's head(FRONT) and tail(REAR) initially point to the array's first index (starting the index of array from 0). 
  • The tail moves ahead as we add elements to the queue, always pointing to the spot where the next element will be inserted, while the head stays at the first index.


Queue Data Structure using Stack...


Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.