有哪些 javascript 树数据结构可用?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8640823/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What javascript tree data structures are available?
提问by ocoutts
Are there good libraries for manipulating trees in javascript? Just to be clear, I am looking for tree as in data structure not display model.
是否有用于在 javascript 中操作树的好库?为了清楚起见,我正在寻找数据结构中的树而不是显示模型。
采纳答案by ty.
Here are some libraries that you may find helpful:
以下是一些可能对您有所帮助的库:
arboreal.js, a "micro-library for traversing and manipulating tree-like data structures" in node.js and the browser.
arboreal.js,node.js 和浏览器中的“用于遍历和操作树状数据结构的微型库”。
buckets, a "complete, fully tested and documented data structure library" that includes BSTs, a heap, and a bunch of other goodies.
buckets,一个“完整的、经过充分测试和记录的数据结构库”,其中包括 BST、一个堆和一堆其他好东西。
回答by jnuno
回答by AturSams
I am not sure what your needs are so this is a shot in the dark. I normally use (for lightweight Javascript) an array of arrays, like this:
我不确定您的需求是什么,所以这是在黑暗中拍摄。我通常使用(对于轻量级 Javascript)一个数组数组,如下所示:
node[i] = [parent, firstChild, secondChild, ... nthChild];
回答by Stephen James
Wish I'd seen that solution before, because those libraries look helpful!
希望我之前看过那个解决方案,因为这些库看起来很有帮助!
Here is one I put together which is an alternative. Meant for traversal, manipulation and loading of hierarchical tree structures from self referencing flat tables, not for balanced binary trees.
这是我放在一起的一个替代方案。用于从自引用平面表中遍历、操作和加载分层树结构,而不是用于平衡二叉树。
回答by Rapha?l Pellicier
Try the DOM
尝试 DOM
var o = document.createElement( 'WHAT_YOU_WANT' )
// o.appendChild( ... )
回答by Chaitanya Chandurkar
I wrote one simple data oriented tree library called data-tree. You can use this to create, traverse and search tree in BFS/DFS fashion. You can also import/export data from tree. Checkout the detailed documentation at: http://cchandurkar.github.io/Data-Tree/
我写了一个简单的面向数据的树库,称为data-tree。您可以使用它以 BFS/DFS 方式创建、遍历和搜索树。您还可以从树中导入/导出数据。查看详细文档:http: //cchandurkar.github.io/Data-Tree/
To use it in a node npm install data-tree
在节点中使用它 npm install data-tree