从简单节点到超级节点的遍历 [英] Traversing from simple node to super node

查看:96
本文介绍了从简单节点到超级节点的遍历的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我目前正在用C ++开发一个程序,该程序可以从环形拓扑中的简单节点中检测超级节点.我的要求是我需要从简单节​​点遍历到超级节点,并突出显示所有可能进入超级节点的路径.这包括超级节点和简单节点之间的环形拓扑.

我想编写一个递归函数来查找路径.请让我知道是否有人对如何开发可检测到它的递归函数有任何想法.

我已经 attached 链接了这些图像,以便更好地理解:

Starting.JPG [ Expected.JPG [

Hi,
I am currently developing a program in C++ which detects super node from a simple node in a ring type topology. My requirement is that I need to traverse from simple node to super node and highlight all the possible paths which are going to super node. This includes ring topology in between super node and simple node.

I would like to write a recursive function to find the path. Please let me know if anyone has any idea about how to develop recursive function which detects it.

I have attached linked these images for better understanding:

Starting.JPG[^]
Expected.JPG[^]

推荐答案

您好,
1.从节点遍历以找出当前节点的所有父节点.

2.保留列表中的所有节点.

3.为所有父节点一个接一个地设置递归循环,直到没有超级节点为止.

4.突出显示收集的节点.




谢谢,
Lokesh Balan

:)
Hi,
1.traverse from the node to find out all the parentnodes of the current node.

2.Keep all the nodes in a list.

3.Set recursive loop for all the parentnode one by one till the super node is not achieved.

4. Highlight the collected nodes.




Thanks,
Lokesh Balan

:)


一旦您具有节点的层次结构,例如节点具有childnodes,而子节点又具有子节点,则可以进行递归搜索.

假设节点A具有子B和子C.说所有节点都具有map子函数,该子函数将被递归调用并将路径传递到子节点.因此,这里A在每个子代中调用递归函数,并将路径AB传递给B,将AC传递给C.

现在说B有两个孩子D&E,但C没有孩子.因此,C将返回空路径.取而代之的是,B将ABD传递给D,将ABE传递给E.现在说D有一个孩子H,这是终点.因此,D将ABDH传递给H,因为它是终点,所以它返回了路径. E的孩子为F,F的孩子为H(端点).因此,E将ABEFH传递给F,F将ABEFH传递给H,然后返回.因此,我们获得了两条路径ABDH和ABEFH,这是我们将无法获得的AC路径,并且最终子代返回null,因为它没有到达终点.

这样,您可以获得最终的有效路径.希望对您有帮助
Once you have the hierarchial structure of the nodes like a node has childnodes and the children has childrens then it is fir for a recursive search.

Say for example Node A has Child B and Child C. Say all the nodes has map childs function which will be recursively called and pass the path so far to the child. So here A call the recursive function in each child and pass path AB to B and AC to C.

Now say B has two children D & E, but C has no children. So C will return a null path. Instead B pass ABD to D and ABE to E. Now say D has a child H which is the end point. So D pass ABDH to H and as it is end point it returns the path. E has a child F and F has the child H (end point). So E pass ABEF to F and F pass ABEFH to H and it returns. So we got two paths ABDH and ABEFH, the AC path we will not get and the end child returns null, because it didn''t reached the end point.

So that way you can get the final valid paths. Hope this helps


这篇关于从简单节点到超级节点的遍历的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆