npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

queuestacklib

v1.0.2

Published

Queue and Stack classes

Downloads

13

Readme

QueueStack

Queue & Stack classes.

NPM

You can import the constructors like so:

const queuestacklib = require("queuestacklib");
const Queue = queuestacklib.Queue;
const Stack = queuestacklib.Stack;

// Using ES6 Destructuring Assignment
const {Queue, Stack} = require("queuestacklib");

Queue

Constructor

new Queue( [ iterable = null [, limit = Number.MAX_SAFE_INTEGER ]] );

A bounded Queue which inherits from a Doubly Linked List.

Constructor Parameters

  • iterable (Optional) Iterable

    The values of the optional Iterable will be used to populate the new Queue.

  • limit (Optional) Number

    A Number which specifies the maximum number of values allowed within the Queue.

Examples

Example 1: Basic Usage:

// Array of arbitrary numbers.
var arr = [1,2,3,4,5];

// New Queue is created using the contents of `arr`.
var queue = new Queue(arr);

// Append "6" to the end of the Queue.
queue.add(6);

// Removes "1" from the beginning of the Queue.
var one = queue.remove();

// Logs 2, 3, 4, 5, 6
for (const num of queue) {
	console.log(num);
}

Instance Properties

Queue.size

Number

Queue.size

A number representing the quantity of values within the Queue.

Queue.limit

Number

Queue.limit

A Number which specifies the maximum number of values allowed within the Queue.


Prototype Methods

Queue.prototype.@@iterator

Iterator

Queue[Symbol.iterator]();

An iterator which yields each value in the Queue.

Examples

Example 1: Basic Usage:

// Array of arbitrary numbers.
var arr = [1,2,3,4,5];

// New Queue is created using the contents of `arr`.
var queue = new Queue(arr);

// Logs 1, 2, 3, 4, and 5.
for (const value of queue) console.log(value);

Queue.prototype.clear

Function

Queue.clear();

Removes all elements from the Queue.

Examples

Example 1: Basic Usage:

// Array of arbitrary numbers.
var arr = [1,2,3,4,5];

// New Queue is created using the contents of `arr`.
var queue = new Queue(arr);

// Queue becomes empty.
Queue.clear();

Queue.prototype.item

Function

Queue.item( index );

Returns the vakue at the specified 0-indexed offset from the beginning of the Queue, or null if it was not found.

Parameters

  • index Number

    An offset from the beginning of the Queue, starting at zero, to look for a value at.

Examples

Example 1: Basic Usage:

// Array of arbitrary numbers.
var arr = [1,2,3,4,5];

// New Queue is created using the contents of `arr`.
var queue = new Queue(arr);

// Returns the value at index 4, the last element in Queue, which contains "5".
var five = queue.item(4);

Queue.prototype.add

Function

Queue.add( element );

Inserts a value at the end of the Queue.

Parameters

  • element Any

    A value to append the Queue with.

Examples

Example 1: Basic Usage:

// Array of arbitrary numbers.
var arr = [1,2,3,4,5];

// New Queue is created using the contents of `arr`.
var queue = new Queue(arr);

// Inserts "6" at the end of the Queue.
queue.add(6);

Queue.prototype.remove

Function

Queue.remove();

Removes and returns an value from the beginning of the Queue.

Examples

Example 1: Basic Usage:

// Array of arbitrary numbers.
var arr = [1,2,3,4,5];

// New Queue is created using the contents of `arr`.
var queue = new Queue(arr);

// Returns "1" and removes it from the beginning of the Queue.
var one = queue.remove();

Queue.prototype.head

Function

Queue.head();

Returns the value at the beginning of the Queue, or null if the Queue is empty.

Examples

Example 1: Basic Usage:

// Array of arbitrary numbers.
var arr = [1,2,3,4,5];

// New Queue is created using the contents of `arr`.
var queue = new Queue(arr);

// Returns "1".
var one = queue.head();

Queue.prototype.end

Function

Queue.end();

Returns the value at the end of the Queue, or null if the Queue is empty.

Examples

Example 1: Basic Usage:

// Array of arbitrary numbers.
var arr = [1,2,3,4,5];

// New Queue is created using the contents of `arr`.
var queue = new Queue(arr);

// Returns "5".
var five = queue.last();

Stack

Constructor

new Stack( [ iterable = null [, limit = Number.MAX_SAFE_INTEGER ]] );

A bounded Stack which inherits from a Doubly Linked List.

Constructor Parameters

  • iterable (Optional) Iterable

    The values of the optional Iterable will be used to populate the new Stack.

  • limit (Optional) Number

    A Number which specifies the maximum number of values allowed within the Stack.

Examples

Example 1: Basic Usage:

// Array of arbitrary numbers.
var arr = [1,2,3,4,5];

// New Stack is created using the contents of `arr`.
var stack = new Stack(arr);

// Append "6" to the end of the Stack.
stack.add(6);

// Removes "6" from the end of the Stack.
var six = stack.remove();

// Logs 1, 2, 3, 4, 5
for (const num of stack) {
	console.log(num);
}

Instance Properties

Stack.size

Number

Stack.size

A number representing the quantity of values within the Stack.

Stack.limit

Number

Stack.limit

A Number which specifies the maximum number of values allowed within the Stack.


Prototype Methods

Stack.prototype.@@iterator

Iterator

Stack[Symbol.iterator]();

An iterator which yields each value in the Stack.

Examples

Example 1: Basic Usage:

// Array of arbitrary numbers.
var arr = [1,2,3,4,5];

// New Stack is created using the contents of `arr`.
var stack = new Stack(arr);

// Logs 1, 2, 3, 4, and 5.
for (const value of stack) console.log(value);

Stack.prototype.clear

Function

Stack.clear();

Removes all elements from the Stack.

Examples

Example 1: Basic Usage:

// Array of arbitrary numbers.
var arr = [1,2,3,4,5];

// New Stack is created using the contents of `arr`.
var stack = new Stack(arr);

// Stack becomes empty.
Stack.clear();

Stack.prototype.item

Function

Stack.item( index );

Returns the vakue at the specified 0-indexed offset from the beginning of the Stack, or null if it was not found.

Parameters

  • index Number

    An offset from the beginning of the Stack, starting at zero, to look for a value at.

Examples

Example 1: Basic Usage:

// Array of arbitrary numbers.
var arr = [1,2,3,4,5];

// New Stack is created using the contents of `arr`.
var stack = new Stack(arr);

// Returns the value at index 4, the last element in Stack, which contains "5".
var five = stack.item(4);

Stack.prototype.add

Function

Stack.add( element );

Inserts a value at the end of the Stack.

Parameters

  • element Any

    A value to append the Stack with.

Examples

Example 1: Basic Usage:

// Array of arbitrary numbers.
var arr = [1,2,3,4,5];

// New Stack is created using the contents of `arr`.
var stack = new Stack(arr);

// Inserts "6" at the end of the Stack.
stack.add(6);

Stack.prototype.remove

Function

Stack.remove();

Removes and returns an value from the end of the Stack.

Examples

Example 1: Basic Usage:

// Array of arbitrary numbers.
var arr = [1,2,3,4,5];

// New Stack is created using the contents of `arr`.
var stack = new Stack(arr);

// Returns "5" and removes it from the end of the Stack.
var one = stack.remove();

Stack.prototype.head

Function

Stack.head();

Returns the value at the beginning of the Stack, or null if the Stack is empty.

Examples

Example 1: Basic Usage:

// Array of arbitrary numbers.
var arr = [1,2,3,4,5];

// New Stack is created using the contents of `arr`.
var stack = new Stack(arr);

// Returns "1".
var one = stack.head();

Stack.prototype.end

Function

Stack.end();

Returns the value at the end of the Stack, or null if the Stack is empty.

Examples

Example 1: Basic Usage:

// Array of arbitrary numbers.
var arr = [1,2,3,4,5];

// New Stack is created using the contents of `arr`.
var stack = new Stack(arr);

// Returns "5".
var five = stack.last();