0

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".

6
  • You can use Javascript array as dictionary. I think JS engine implementation should optimize the operations to some degree. Commented May 31, 2012 at 5:36
  • 1
    possible duplicate of javascript data structures library Commented May 31, 2012 at 5:37
  • 1
    @nhahtdh: Why an array? A normal Object works just fine. Commented May 31, 2012 at 5:38
  • @icktoofay: I think you are right. I'm still quite novice with JS. Commented May 31, 2012 at 5:39
  • @icktoofay yup. it's a duplicate. I swear I did look before I posted the question, so I'm not sure why I wasn't seeing that one... thanks for the reference. Commented May 31, 2012 at 6:34

2 Answers 2

1

Google's Closure Library should have most of what you need: https://developers.google.com/closure/library/

Sign up to request clarification or add additional context in comments.

Comments

-1

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)

2 Comments

Please don't just post some tool or library as an answer. At least demonstrate how it solves the problem in the answer itself.
Added examples how to use this lib

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.