QueueArray()

This class is a Queue data structure based on JavaScript Array. This data structure is a FIFO implmentation, in other words, the first element to enter is the first to exit.

new QueueArray()

Creates a QUEUE

Example
const { QueueArray } = require('data-structures-algorithms-js');
const queue = new QueueArray();

Methods

back() → {*|undefined}

Returns the last element of the Queue

Returns:
* | undefined -

Returns the element on the back or undefined if queue is empty

Example
const { QueueArray } = require('data-structures-algorithms-js');
const queue = new QueueArray();

queue.back();// returns undefined

queue.push(23);
queue.push(89);

queue.back(); //returns 89

clear()

Resets the Queue

Example
const { QueueArray } = require('data-structures-algorithms-js');
const queue = new QueueArray();

queue.push(15);

queue.clear(); // now queue is empty

front() → {*|undefined}

Returns the first element of the Queue

Returns:
* | undefined -

Returns the element on the front or undefined if queue is empty

Example
const { QueueArray } = require('data-structures-algorithms-js');
const queue = new QueueArray();

queue.front();// returns undefined

queue.push(23);
queue.push(89);

queue.front(); //returns 23

isEmpty() → {Boolean}

Returns if the Queue is empty

Returns:
Boolean
Example
const { QueueArray } = require('data-structures-algorithms-js');
const queue = new QueueArray();

queue.isEmpty(); // returns true;

queue.push(23);

queue.isEmpty(); //returns false;

pop()

Removes the first element from the Queue

Example
const { QueueArray } = require('data-structures-algorithms-js');
const queue = new QueueArray();

queue.push(3);
queue.push(9);

queue.pop(); //removes number 9

push(element)

Adds a element to the end of the Queue

Parameters:
Name Type Description
element *

Element passed to insert

Example
const { QueueArray } = require('data-structures-algorithms-js');
const queue = new QueueArray();

queue.push(5); //inserts 5 to the end of the queue

size() → {Number}

Returns the size of the Queue

Returns:
Number -

The number of elements in the Queue

Example
const { QueueArray } = require('data-structures-algorithms-js');
const queue = new QueueArray();

queue.size(); // returns 0;

queue.push(8);

queue.size(); //returns 1;