你用什么java数据结构/库来创建树

发布于 2024-09-08 23:43:13 字数 1539 浏览 0 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

做个ˇ局外人 2024-09-15 23:43:13

查看 DefaultMutableTreeNode。它不通用,但在其他方面似乎符合要求。尽管它位于 javax.swing 包中,但它不依赖于任何 AWT 或 Swing 类。事实上,源代码实际上有注释 // ISSUE: this class dependents Nothing in AWT -- move to java.util?

Check out DefaultMutableTreeNode. It's not generic, but otherwise seems to fit the bill. Even though it's in the javax.swing package, it doesn't depend on any AWT or Swing classes. In fact, the source code actually has the comment // ISSUE: this class depends on nothing in AWT -- move to java.util?

笛声青案梦长安 2024-09-15 23:43:13

使用泛型实现树非常简单,为什么不自己尝试一下呢?如果您对泛型不满意,可以尝试声明一个包含实现接口的元素的树,然后让所有不同的区域元素实现该接口。

Implementing a tree using generics is pretty simple, why not give it a try yourself? If you're not comfortable with generics, you can try declaring a tree that contains elements that implement an interface, then just have all your various region elements implement that interface.

孤城病女 2024-09-15 23:43:13

您是指树形小部件还是树状数据结构?如果您谈论的是 Tree 小部件,那么 Swing 有一个实现。

JTree

Do you mean a Tree Widget or a tree like data structure? If you are talking about a Tree widget, then Swing has an implementation.

JTree

孤千羽 2024-09-15 23:43:13

您所描述的更像是文档对象模型(DOM)。通常,当人们提到“树”数据结构时,他们谈论的是平衡二叉树(如红黑树,它确实存在于 Java 集合库中)。但这些类型的树仅用于快速有序插入和查找。

不管怎样,大多数时候,当人们使用 DOM 时,他们是在读取或写入 XML,但是您没有理由不能将 DOM 用于您自己的任意分层数据。即使您从未将其持久化为 XML。

What you're describing is much more like a Document Object Model (DOM). Usually when people refer to a "Tree" data structure, they're talking about a balanced binary tree (like a red-black tree, which certainly does exist in the Java collections library). But those kinds of trees are just for fast in-order insertions and lookups.

Anyhow, most of the time, when people use a DOM, they're reading or writing XML, but there's no reason you couldn't use a DOM for your own arbitrary hierarchical data. Even if you never persist it to XML.

最美不过初阳 2024-09-15 23:43:13

像这样的http://www.java-tips.org/java-se-tips/java.lang/red-black-tree-implementation-in-java.html 工作吗?

另外,从 OpenJDK 的 java.util.TreeMap 源开始怎么样? http://download.java.net/openjdk/jdk7/

Would something like this http://www.java-tips.org/java-se-tips/java.lang/red-black-tree-implementation-in-java.html work?

Also, how about starting with the java.util.TreeMap source from the OpenJDK? http://download.java.net/openjdk/jdk7/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文