在二叉树中访问节点父节点的父节点

时间:2015-04-05 02:26:20

标签: c pointers binary-search-tree

我有一个像这样的二叉搜索树结构:

typedef struct Tree{
    long int key;
    struct Tree *left, *right, *parent;

}Tree;

我正在使用指针(父)来跟踪节点的父节点。

插入一些节点后,我遇到了一些麻烦。

结果树是:

    3
 /     \
1       11
 \     / 
  2   8
when I try to access (8)->parent, I get 11... that's right.

When I try to access (11)->parent, I get 3... all good.

But if I try (8)->parent->parent the result is NOT 3

有没有人有任何线索为什么它不给节点3?

0 个答案:

没有答案