Is there a javascript library that provides common data structures, e.g. priority queue, dictionary, and successor queries (balanced trees)? I could roll my own, but I'd rather have a black-box, especially if it's already been "optimized".
2 Answers
Google's Closure Library should have most of what you need: https://developers.google.com/closure/library/
Comments
use below lib of already implemented collection classes: https://www.npmjs.com/package/collectiondatalib
Examples:
const lib = require('collectiondatalib') lib.Search.binary_search([1,2,3,4,5], 5)
4
lib.Sort.bubble_sort([3,5,1,4,2])
[ 1, 2, 3, 4, 5 ]
lib.Sort.merge_sort([3,5,1,4,2])
[ 1, 2, 3, 4, 5 ]
let list = new lib.SinglyLinkedList()
list.push(12) list.push(13) list.push(14) console.log(list)
SinglyLinkedList { head: Node { val: 12, next: Node { val: 13, next: [Node] } }, tail: Node { val: 14, next: null }, length: 3 }
let queue=new lib.PriorityQueue()
queue.enqueue("hello",5)
queue.enqueue("hi",4)
Objectworks just fine.