1.1.0 • Published 5 years ago
@typemon/stack v1.1.0
Stack
push push push peek pop
Usage
$ npm install @typemon/stack
import { Stack } from '@typemon/stack';
const stack: Stack<string> = new Stack(['a']); // ['a'] count = 1
stack.push('b'); // ['a', 'b'] count = 2
stack.push('c'); // ['a', 'b', 'c'] count = 3
stack.peek(); // 'c' ['a', 'b', 'c'] count = 3
stack.pop(); // 'c' ['a', 'b'] count = 2
Get Item
const stack: Stack<string> = new Stack(['a']);
stack.get(0); // 'a'
stack.get(1); // error: 'The index is out of range.'
stack.get(-1); // error: 'The index is out of range.'