简体   繁体   English

JUNG在树上指定左右儿童

[英]JUNG specifying left and right children in a tree

I am currently making a binary tree visualization application with JUNG using DelegateTree . 我目前正在使用DelegateTree与JUNG一起构建二叉树可视化应用程序。 However, I fail to find a way to explicitly state whether a node should be a left or a right child. 但是,我找不到明确说明节点应该是左子节点还是右子节点的方法。

Initially I thought that I only need to use addChild(edge, parent, child) and just keep adding nodes in the same order. 最初我认为我只需要使用addChild(edge, parent, child)并继续以相同的顺序添加节点。 Later tho, I realized that this method does not always work. 后来,我意识到这种方法并不总是有效。 At first the produced tree seems correct but once it gets past height 3, it starts messing up and switching nodes and eventually whole subtrees in no particular fashion. 起初生成的树似乎是正确的,但是一旦它超过高度3,它就会开始搞乱,并且不会以特定的方式切换节点和最终的整个子树。

DelegateTree does not itself guarantee any particular ordering for the iteration over neighbors (children). DelegateTree本身并不保证对邻居(子)的迭代的任何特定排序。 If its input graph guarantees this ordering (see JUNG: placing tree nodes in order ) then you should be OK. 如果它的输入图保证了这种顺序(参见JUNG:按顺序放置树节点 )那么你应该没问题。

You also can use OrderedKAryTree for this: http://jung.sourceforge.net/doc/api/edu/uci/ics/jung/graph/OrderedKAryTree.html 你也可以使用OrderedKAryTree: http ://jung.sourceforge.net/doc/api/edu/uci/ics/jung/graph/OrderedKAryTree.html

Since you know that you have a binary tree in particular, you can also create a more efficient implementation of your own that assumes that all nodes have <= 2 children. 由于您知道特别具有二叉树,因此您还可以创建自己的更高效的实现,假定所有节点都具有<= 2个子节点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM