js-data-structure-library

A JavaScript Data Structure Library

Usage no npm install needed!

<script type="module">
  import jsDataStructureLibrary from 'https://cdn.skypack.dev/js-data-structure-library';
</script>

README

js-data-structure-library

Stack

methods

  • push: add an element to the end of this stack
  • pop: delete an element from the end of this stack
  • peek: return the front element of this stack
  • isEmpty: return this stack is empty or not
  • clear: clear all elements of this stack
  • size: return length of this stack
  • toString: to show elements of this stack

How to use?

you can use Stack like this:

const stack = new Stack<number>()
stack.push(1)
stack.push(2)
stack.pop()
stack.peek() // 1
stack.isEmpty() // false
stack.size() // 1
stack.clear()
stack.size() // 0