Ads

banner image

Queue



A queue is an ordered collection of items that follows the First In First Out (FIFO) principle. And just like stack, it’s a linear data structure. New items are added to the queue at the tail while removal of items happens at the front. A typical example of a queue is customers queuing up to check out at the grocery store. The first in line is attended to first
. To store data, a list/array can be used. 
There are 2 major operations that can be carried out in a queue; enqueue and dequeue. Other operations include;

  1. front: returns the first element from the queue. This is always the first element that’s added, which will also be the first element to be removed. With this operation, the list/array is not modified.
  2. isEmpty: checks if the queue storage contains any item or if it’s empty. Returns true or false.
  3. size: returns the length of items in the queue.



Queue Queue Reviewed by Idowu Wasiu on December 31, 2019 Rating: 5

No comments:

Powered by Blogger.