Data structures - Queue implementation in javascript

Kids in Queue


The Queue is a FIFO (first-in, first-out) data structure. It means that any data stored first will be the first to be removed - just like a queue.

The person first in a queue is the one who gets out of the queue first!

Here is an example of how the queue can be implemented in javascript. The queue has the following functions:

  • enqueue: attaches an item to the end of the queue

  • dequeue: detaches the first item from the queue

  • first: returns the first item of the queue without removal, just like peeking in the Stack data structure

Here is the complete source code