Skip to content
JavaScript data structure implemented in ES6.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github
lib-exec
lib-test
lib
questions
src
test
.babelrc
.eslintignore
.eslintrc
.gitignore
.jshintignore
.jshintrc
.travis.yml
CONTRIBUTING.md
LICENSE
README.md
package.json
webpack.config.babel.js

README.md

JavaScript Data Structure

Build Status Codecov Coverage npm version npm download MTI License semantic-release CII Best Practices

JavaScript data structure implemented in ES6. This library covers the implementation of the basic data structures, including graph(Breath-first Search, Depth-first search), binary search tree, queue, and some sorting (Quick Sort, Merge Sort) and search algorithm for array.

The code here is rewriting from Learning JavaScript Data Structures and Algorithms to es6 with some enhancements on performance, and added the unit tests for each of the data structure.

How to install and run the test

npm install;
npm test;

How to commit the code to release a new version via semantically-released

npm run commit;

Usage

// Graph
import { Graph } from 'js-data-structure';
const graph = new Graph();
graph.addVertex('A');
graph.addVertex('B');
graph.addVertex('C');
graph.addVertex('D');
graph.addVertex('E');
graph.addVertex('F');
graph.addVertex('G');
graph.addVertex('H');
graph.addVertex('I');
graph.addEdge('A', 'B');
graph.addEdge('A', 'C');
graph.addEdge('B', 'D');
graph.addEdge('C', 'F');
graph.addEdge('D', 'E');
graph.addEdge('E', 'G');
graph.addEdge('E', 'I');
graph.addEdge('F', 'E');
graph.addEdge('G', 'H');
graph.addEdge('H', 'I');

/*
************************
Graph generated
************************
 A -> B
 |    |
 \/   \/
 C    D
 |    |
 \/   \/
 F -> E  -> G
      |     |
      \/    \/
      I  <- H
************************
*/

// get the shortest path
const shortestPath = graph.getShortestPath('A', 'I');
console.log(shortestPath) // ['A', 'B', 'D', 'E', 'I']


include in the browser

import { Sorting } from 'js-data-structure';
console.log(Sorting.bubbleSort([5, 4, 3, 2, 1]));

Contact us

Please chat with us via https://gitter.im/almandsky-js-data-structure/community

License

MIT © Sky Chen

You can’t perform that action at this time.