queue-typed
v1.53.2
Published
Queue, ArrayQueue. Javascript & Typescript Data Structure.
Downloads
2,363
Maintainers
Keywords
Readme
What
Brief
In the usual gig, we make do with Array.push and Array.shift to play Queue in JavaScript, but here's the kicker – native JavaScript Array isn't exactly Queue VIP. That shift move? It's a bit of a slow dance with a time complexity of linear time complexity O(n). When you're working with big data, you don't want to be caught slow-shifting. So, we roll up our sleeves and craft a Queue that's got a speedy constant time complexity O(1) Queue.enqueue(), a snappy O(1) Queue.dequeue(), and a lightning-fast O(1) Queue.getAt(). Yep, it's Queue-tastic!
more data structures
This is a standalone Queue data structure from the data-structure-typed collection. If you wish to access more data structures or advanced features, you can transition to directly installing the complete data-structure-typed package
How
install
npm
npm i queue-typed --save
yarn
yarn add queue-typed
methods
Queue LinkedListQueue
snippet
TS
import {Queue} from 'queue-typed';
// /* or if you prefer */ import {Queue} from 'queue-typed';
const queue = new Queue<number>();
for (let i = 0; i < magnitude; i++) {
queue.enqueue(i);
}
for (let i = 0; i < magnitude; i++) {
queue.dequeue();
}
for (let i = 0; i < magnitude; i++) {
console.log(queue.getAt(i)); // 0, 1, 2, 3, ...
}
JS
const {Queue} = require('queue-typed');
// /* or if you prefer */ const {Queue} = require('queue-typed');
const queue = new Queue();
for (let i = 0; i < magnitude; i++) {
queue.enqueue(i);
}
for (let i = 0; i < magnitude; i++) {
queue.dequeue();
}
for (let i = 0; i < magnitude; i++) {
console.log(queue.getAt(i)); // 0, 1, 2, 3, ...
}
API docs & Examples
Examples Repository