js-structures

1.0.5 • Public • Published

JS Structures

Set of data structures implemented in Javascript. Currently the following structures are implemented:

LinkedList

This a a doubly linked list implementation. Each node of the list is always linked to the previus and successive node with the properties prev and next.

The node object stored in the list has the following schema

{
    "title": "List node",
    "type": "object",
    "properties": {
        "data": {
            "type": "any"
        },
        "prev": {
            "type": "object"
        },
        "next": {
            "type": "object"
        }
    }
}

Methods

  • add(data) - Append a node with arbitrary data to the end of the list list.
  • addFirst(data) - Insert a node with arbitrary data at the beginning of the list.
  • remove(index) - Remove the node at the given index without retrieving it. Throws RangeError if the list is empty or if the index is too small or too big.
  • removeFirst() - Removes the first node of the list, it's a shortcut for remove(0)
  • removeLast() - Removes the last node of the list, it's a shortcut for remove(List.size() - 1)
  • peek(index) - Retrieve the node at the given position
  • get(index) - Retrieve and remove the node at the given position
  • size() - Get the current size of the list

Queue

It's a collection that order elements with FIFO order. It's baked by the LinkedList so the elements contained in the queue are the same as the list but without access to the other elements.

Methods

  • enqueue(data) - Add data to the queue
  • dequeue() - Retrieve and remove the next element in the queue if any, otherwise return null
  • peek() - Retrieve just the next element from the queue, without removing it.
  • size() - Return the queue size.

Stack

It's a collection that order elements with LIFO order. It's baked by the LinkedList so the elements contained in the stack are the same as the list but without access to the other elements.

Methods

  • push(data) - Add data to the stack
  • pop() - Retrieve the next element of the stack if any, otherwise return null
  • size() - Return the stack size

Swag

NPM Status

NPM

Build

wercker status

Code climate

Code Climate Test Coverage

Readme

Keywords

none

Package Sidebar

Install

npm i js-structures

Weekly Downloads

0

Version

1.0.5

License

none

Last publish

Collaborators

  • ninjatux