Javascript:我需要一个良好的数据结构来保持排序列表 [英] Javascript: I need a good data structure to keep a sorted list
问题描述
虽然我不知道在哪里可以找到Javascript的数据结构的好的实现。
帮助赞赏。
取决于你为什么需要它例如,如果您只需要顶级元素,则二进制堆可能对您而言是正确的。否则,对数组实现binarySearch和insertSorted函数,不应超过十五行。除非你计划拥有成千上万的元素;那么只需要批量插入,然后使用内置函数排序就更有意义了。
This would probably be implemented as a tree or something? My point is it needs to be efficient.
I don't know where to find good implementations of data structures for Javascript for something like this, though. I don't want to have to roll my own if I can avoid it.
Help appreciated.
Depends why you need it. For instance, if you only need the top element, this binary heap might be okay for you. Otherwise, implement a binarySearch and insertSorted functions for arrays, should not be more than ten-fifteen lines. Unless you plan on having thousands upon thousands of elements; then it makes more sense to just insert in bulk and then sort using the builtin.
这篇关于Javascript:我需要一个良好的数据结构来保持排序列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!