data-struct-js
About this package
Implement of common data structures using javascript. besides supplied by JS, such as Array/Set(WeakSet)/Map(WeakMap)
source code
Write in ES6, using babel to convert to ES5.
You can download and run npm run compile
with customized babel setting to meet your needs.
How to use
more examples see
data-struct-js/examples
install the package
npm install --save-dev data-struct-js
or
npm i -D data-struct-js
then use the data-structures supplied simply as below
const Stack Queue PriorityQueue LinkedList DoublyLinkedList CircleLinkedList HashTalbe BinarySearchTree RedBlackTree = // Or ↓// import {// Stack,// Queue,// PriorityQueue,// LinkedList,// DoublyLinkedList,// CircleLinkedList,// HashTalbe,// BinarySearchTree,// RedBlackTree,// } from 'data-struct-js'// -> may need webpack and bable-loader environment //----------------------------// Stacklet stack = stackstackstack // Element2stack // Element1 //----------------------------// Queuelet queue = queuequeuequeue // Firstqueue // Second //----------------------------// PriorityQueuelet pq = pqpqpqpqpqpq// -->// 0: QueueElement {__element: "2-CPU", __priority: 0, toString: ƒ}// 1: QueueElement {__element: "1-Memory", __priority: 1, toString: ƒ}// 2: QueueElement {__element: "3-HardDisk", __priority: 2, toString: ƒ}// 3: QueueElement {__element: "4-Display", __priority: 3, toString: ƒ}// 4: QueueElement {__element: "5-OperatingSystem", __priority: 5, toString: ƒ}// 5: QueueElement {__element: "6-Aplication", __priority: Infinity, toString: ƒ} //----------------------------// LinkedListlet linkedList = linkedListlinkedListlinkedList//... //----------------------------// DoublyLinkedListlet doublyLinkedList = const traverseFunc = { console}doublyLinkedListdoublyLinkedListdoublyLinkedListdoublyLinkedListdoublyLinkedListdoublyLinkedList//... //----------------------------// CircleLinkedListlet circle = circlecirclecirclecirclefor let j = 0; j < 9; j++ const item = circle console //----------------------------// HashTablelet hashTable = // AddhashTablehashTablehashTablehashTable// UpdatehashTable// DeletehashTable // truehashTable // false//... //----------------------------// BinarySearchTreelet bst = bstbstbstbstbstbstbstbstbstbstbstbstbstbstbstbst/** * * 8 * ------------------ * | | * 6 13 * --------- --------------- * | | | | * 4 7 11 20 * ----- ------- ---------- * | | | | | | * 3 5 10 12 16 35 * ----- ------ * | | * 9 18 * ----- * | * 19 * */ var { console}bst bst// ⬇️/** * * 8 * ------------------ * | | * 6 16 * --------- --------------- * | | | | * 4 7 11 18 * ----- ------- ---------- * | | | | | * 3 5 10 12 19 * ----- ------ * | | * 9 20* ----- * | * 35 * *///...
Data structures
Implement data structures:
- Stack
- Queue
- PriorityQueue
- LinkedList
- DoublyLinkedList
- CircleLinkedList
- CircleDoublyLinkedList
- HashTalbe
- BinarySearchTree
- RedBlackTree
- UndirectedGraph
- DirectedGraph
Original data structures in JavaScript:
- Array
- Set/WeakSet
- Map/WeakMap
⬆️ not in this library since you could use them directly.
License
MIT
Feel free to use it.