Skip to main content
Home

latest
Works with
This package works with Node.js, Deno, BunIt is unknown whether this package works with Cloudflare Workers, Browsers
It is unknown whether this package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
It is unknown whether this package works with Browsers
JSR Score100%
Downloads1/wk
Published2 years ago (1.0.0)

A class queue implementation in Typescript for any generic type 'T'

TypeScript Queue Data Structure

This project provides a simple implementation of a queue data structure in TypeScript. A queue is a linear data structure that follows the First In, First Out (FIFO) principle. Elements are added to the rear and removed from the front of the queue.

This queue implementation supports generic types, allowing you to use it with any data type. It provides methods for adding, removing, and inspecting elements in the queue.

Table of Contents

Usage

To use this queue data structure in your TypeScript projects, you can follow these steps:

  1. Add this library to your local project with jsr:

    # Deno
    deno add @cm-iv/queue
    # npm
    npx jsr add @cm-iv/queue
    # pnpm
    pnpm dlx jsr add @cm-iv/queue
    # Bun
    bunx jsr add @cm-iv/queue
    
  2. Import the Queue class from this module into your TypeScript files:

    import { Queue } from '@cm-iv/queue';
    
  3. Create a new instance of the Queue class:

    const queue = new Queue<number>(); // Create a queue of numbers
    
  4. Use the queue methods to manipulate and retrieve data:

    queue.enqueue(5);       // Enqueue an element to the rear of the queue
    queue.dequeue();        // Dequeue an element from the front of the queue
    queue.peek();           // Peek at the front element without removing it
    queue.isEmpty();        // Check if the queue is empty
    queue.size();           // Get the size of the queue
    queue.clear();          // Clear the queue
    queue.print();          // Print the queue elements
    

Methods

enqueue(element: T): void: // Adds an element to the rear of the queue.
dequeue(): T | undefined: // Removes and returns the front element from the queue.
peek(): T | undefined: // Returns the front element of the queue without removing it.
isEmpty(): boolean: // Checks if the queue is empty.
size(): number: // Returns the size of the queue.
clear(): void: // Removes all elements from the queue.
print(): void: // Prints the elements of the queue.

License

This project is licensed under the MIT License

Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@cm-iv/queue

Import symbol

import * as queue from "@cm-iv/queue";
or

Import directly with a jsr specifier

import * as queue from "jsr:@cm-iv/queue";

Add Package

pnpm i jsr:@cm-iv/queue
or (using pnpm 10.8 or older)
pnpm dlx jsr add @cm-iv/queue

Import symbol

import * as queue from "@cm-iv/queue";

Add Package

yarn add jsr:@cm-iv/queue
or (using Yarn 4.8 or older)
yarn dlx jsr add @cm-iv/queue

Import symbol

import * as queue from "@cm-iv/queue";

Add Package

vlt install jsr:@cm-iv/queue

Import symbol

import * as queue from "@cm-iv/queue";

Add Package

npx jsr add @cm-iv/queue

Import symbol

import * as queue from "@cm-iv/queue";

Add Package

bunx jsr add @cm-iv/queue

Import symbol

import * as queue from "@cm-iv/queue";