【发布时间】:2011-03-13 23:03:19
【问题描述】:
如何在C(非C++)中有效地遍历树的每个节点而不递归?
假设我有该树的以下节点结构:
struct Node
{
struct Node* next; /* sibling node linked list */
struct Node* parent; /* parent of current node */
struct Node* child; /* first child node */
}
- 这不是家庭作业。
- 我更喜欢深度优先。
- 我更喜欢不需要额外的数据结构(例如堆栈)。
- 我更喜欢在速度方面最有效的方式(而不是空间)。
- 您可以更改或添加
Node结构的成员以存储更多信息。
【问题讨论】:
-
任意顺序,最好是深度优先
-
我编辑了问题标题(添加了“无堆栈”),以便在有人搜索特定需求时清楚说明
标签: c data-structures recursion tree traversal