Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

ts-data.stack

ts-data1.2kMIT1.0.6TypeScript support: included

The Stack (LIFO) data structure in TypeScript.

TypeScript, data, structure, stack, LIFO

readme

ts-data.stack

A stack implemented in TypeScript.

Installation

$ npm install ts-data.stack

Usage

import Stack from "ts-data.stack";

let stack = new Stack<number>();

stack.push(3);
stack.push(7);

stack.count(); // 2
stack.isEmpty(); // false

stack.peek(); // 7

stack.pop(); // 7
stack.pop(); // 3

stack.isEmpty(); // true

Documentation

Stack<TData>()

A stack containing TData types. The constructor takes no arguments.

count(): number

Get the count of items in the stack.

isEmpty(): boolean

True if the stack is empty, false if it contains any elements.

push(value: TData): void

Pushes value to the top of the stack.

pop(): TData

Pop the top value off of the stack and return it.

peek(): TData

Get the top value of the stack without removing it from the stack.

License

Licensed under the MIT License.