【发布时间】:2012-06-26 01:14:06
【问题描述】:
我有一个父/子 ID 列表,并希望获取给定父 ID 的所有子 ID。没有 null 父级(顶级 ID 不会显示为子 ID)。
目前,父/子 ID 被记录为列表中的 KeyValuePair,但是如果这样会更好,可以轻松地将其更改为另一个数据结构:
List<KeyValuePair<int, int>> groups = new List<KeyValuePair<int, int>>();
groups.Add(new KeyValuePair<int,int>(parentID, childID));
例如,这里是示例父/子。父母 27 的孩子将是 5944, 2065, 2066, 2067, 6248, 6249, 6250。
Parent Child
27 1888
1888 5943
1888 5944
5943 2064
5943 2065
5943 2066
5943 2067
2064 6248
2064 6249
2064 6250
任何帮助将不胜感激!
【问题讨论】:
-
您尝试了哪些方法,哪些方法无效?走过一棵树是相当标准的任务......所以现在有点不清楚问题是什么。
标签: c# .net algorithm recursion relationship