TreeNode 广度优先枚举?
现在我的循环是
for (TreeNode n = e.Node.FirstNode; n != null; n = n.NextNode)
,我的数据就像
a
a1
a2
b
b1
我只想枚举宽度(a,b等,而不是a1,a2等)。 我该怎么做呢?
Right now my loop is
for (TreeNode n = e.Node.FirstNode; n != null; n = n.NextNode)
and my data is something like
a
a1
a2
b
b1
I want to enum breadth only (a, b etc, not a1, a2 etc). How do i do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
广度优先枚举通常是通过使用某种队列作为辅助数据结构来完成的。
首先将根推入队列。
然后,当队列中有东西时:
队列。
Breadth first enumeration is typically done by using a queue of some sort as an ancillary data structure.
First push the root onto the queue.
Then, while there is something in the queue:
the queue.
尝试
您可能必须检查空父级并使用
这应该涵盖广度优先算法(抱歉我没有测试过它)
Try
you might have to check for a null parent and use
This should cover the breadth first algorithm (sorry I haven't tested it)
修改bstoney提供的代码
1. 将根节点压入currentLevel队列
2.标记nextLevel = new Queue();
Modify code provided by bstoney
1. push root node to currentLevel queue
2. mark nextLevel = new Queue();