Queue

In computer science, a queue is a collection of entities that are maintained in a sequence and can be modified by the addition of entities at one end of the sequence and the removal of entities from the other end of the sequence.

By convention, the end of the sequence at which elements are added is called the back, tail, or rear of the queue, and the end at which elements are removed is called the head or front of the queue, analogously to the words used when people line up to wait for goods or services.

Read full: wiki/queueopen in new window

Import

import {Queue} from "@raikuxq/alg-ds/lib/exports/data-structures";

API reference

Queue API: /api/data-structures/queue

Example usage

import {Queue} from "@raikuxq/alg-ds/lib/exports/data-structures";

const queue = new Queue<string>();

queue.push("John");
queue.push("Mary");
queue.push("Kate");

queue.peek(); // John
queue.pop(); // John
queue.peek(); // Mary
queue.has("John"); // false