简体   繁体   English

在NON二叉树中查找节点[Java]

[英]Finding a node in a NON binary tree [Java]

I want to find a node of type T that is located somewhere in a non-binary tree in Java. 我想找到一个类型T的节点,该节点位于Java的非二叉树中的某处。

Can it be done both recursively and non recursively? 可以递归和非递归地完成吗?

I thought of applying the rules of binary tree search but without the left and right stuff, but I can't get the idea on how to do it. 我本来想应用二叉树搜索规则,但是没有左右两边的东西,但是我不知道该怎么做。

It depends on if a node in this tree has a fixed number of possible descendants. 这取决于该树中的节点是否具有固定数量的可能后代。 If it does then you can basically just use the same functions with n more if statements for each possible child. 如果是这样,那么您基本上可以对每个可能的子代使用相同的功能,并使用n个以上if语句。 But, if the number of descendants is not fixed then you're dealing with something closer to a graph. 但是,如果后代的数量不固定,那么您正在处理的是更接近图的事物。 In that case you have to use a graph algorithm. 在这种情况下,您必须使用图形算法。

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

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