UNPKG

typescript-ds-lib

Version:

A collection of TypeScript data structure implementations

58 lines 1.49 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Queue = void 0; const linked_list_1 = require("./linked-list"); const base_collection_1 = require("./base-collection"); class Queue extends base_collection_1.BaseCollection { items; constructor() { super(); this.items = new linked_list_1.LinkedList(); } /** * Adds an element to the back of the queue. */ push(element) { this.items.pushBack(element); } /** * Removes and returns the front element from the queue, or undefined if queue is empty. */ pop() { return this.items.popFront(); } /** * Returns the front element of the queue without removing it, or undefined if queue is empty. */ front() { return this.items.get(0); } /** * Checks if the queue is empty. Returns true if the queue is empty, false otherwise. */ isEmpty() { return this.items.isEmpty(); } /** * Returns the number of elements in the queue. */ size() { return this.items.size(); } /** * Removes all elements from the queue. */ clear() { this.items.clear(); } /** * Checks if two queues are equal. */ equals(other) { if (!other || !(other instanceof Queue)) return false; return this.items.equals(other.items); } } exports.Queue = Queue; //# sourceMappingURL=queue.js.map