@utilityjs/queue
v2.0.0
Published
An implementation of Queue data structure.
Maintainers
Readme
UtilityJS | Queue
A First-In-First-Out (FIFO) queue data structure.
Features
- FIFO Operations: Enqueue and dequeue elements
- Peek Support: View front element without removal
- TypeScript Support: Full generic type safety
Installation
npm install @utilityjs/queueor
pnpm add @utilityjs/queueUsage
import { Queue } from "@utilityjs/queue";
const queue = new Queue<number>();
queue.enqueue(1);
queue.enqueue(2);
queue.enqueue(3);
queue.peek(); // 1
queue.dequeue(); // 1
queue.dequeue(); // 2
queue.isEmpty(); // falseAPI
Queue<T>
Constructor
new Queue<T>()- Creates an empty queue
Methods
isEmpty(): boolean- Check if the queue is emptyenqueue(value: T): void- Add element to the reardequeue(): T | null- Remove and return the front elementpeek(): T | null- View the front element without removing
Contributing
Read the contributing guide to learn about our development process, how to propose bug fixes and improvements, and how to build and test your changes.
License
This project is licensed under the terms of the MIT license.
