如何递归地找到子节点的子节点 [英] How to find child's of child node recursively

查看:601
本文介绍了如何递归地找到子节点的子节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个根节点及其子节点,子节点也包含子节点,并且他们的子节点也包含子节点,谁能告诉我如何通过递归找到它,因为它将一直检查子节点的子节点,并且同时将它们添加到树视图中,

例如:
我有root 1
1 ---
2 --- 4
.--- 5 --- 6
. --- 7
3

我正在通过特定ID搜索孩子的孩子,当它获得0个父ID时,它会停止searcgubg.
在此先感谢

i have a root node and its childs,childs node also contains child,and their child also contain childs,can any one tell me how to find this through recursively because it will check child''s of child till end, and simaltanously add them to treeview,

e.g:
i have root 1
1---
2---4
.---5---6
. ---7
3

i am searching for childs of child through a particular id and it stop the searcgubg when it gets 0 parent id.
thanks in advance

推荐答案

您可以递归地进行操作,如下所示:
You can do it recursively, something like this:
void getChildren() {
   System.Console.WriteLine(this.ToString());
   foreach(child Node in Nodes) {
      child.getChildren();
   } 
}


祝你好运!


Good luck!


我想类似的东西应该可以工作(伪代码:伪测试过的...)
I suppose something like this should work (pseudo-code: pseudo-tested...)
Go(Node node)
{
  if (!node) return;
  // do whatever you need to do with node
  Go(node.Sibling);
  Go(node.Child);
}


这篇关于如何递归地找到子节点的子节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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