是否可以将节点置于当前节点之上?

时间:2012-05-05 09:50:37

标签: c tree binary-tree tree-traversal

我被问到一个问题,当我遍历我的二叉树时,是否可以将节点置于当前节点之上?作为双重链表。

1 个答案:

答案 0 :(得分:2)

如果您将其构建为双链接,则是,转到“父”属性。抽象例子:

struct node {
    struct node *parent; // << this is the parent, just access it
    struct node *rchild;
    struct node *lchild;
    int val;
}

否则,您需要在每次访问子节点时缓存前一个节点。

请注意,双重链接列表与二元不同(在列表中,每个项目都有一个子项)。