線索二叉樹

2021-08-17 22:59:29 字數 693 閱讀 4519

二叉樹的線索化的主要思想是將為使用的左右子樹的指標利用,左指標指向前驅節點,右指標指向後繼節點。

#include #include typedef enum //定義線索二叉樹標誌

pointertag;

typedef struct binode

binode, *bitree;

bitree pre; //定義pre為全域性變數,為二叉樹線索化中的前節點

void creattree (bitree *t)

else

}void inthread (bitree t) //二叉樹線索化

else

else

pre = t;

inthread(t->rchild);

}}bitree inorderthread (bitree t)

else

return thr;

}void inorderprint (bitree t)

printf("%d\n", p->data);

while(p->rtag == thread && p->rchild != t)

p = p->rchild;

}// printf("%d\n", p->data);

}int main ()

線索二叉樹

當用二叉鍊錶作為二叉樹的儲存結構時,因為每個結點中只有指向其左 右兒子結點的指標,所以從任一結點出發只能直接找到該結點的左 右兒子。在一般情況下靠它無法直接找到該結點在某種遍歷序下的前驅和後繼結點。如果在每個結點中增加指向其前驅和後繼結點的指標,將降低儲存空間的效率。我們可以證明 在n個結點的二叉鍊...

線索二叉樹

1.線索二叉樹結構和操作定義 threadbintree.h 功能 線索標誌域所有值 typedef enumnodeflag 功能 線索二叉樹結構體 typedef struct threadtreethreadbintree 前驅節點指標 threadbintree previous null ...

線索二叉樹

原始碼 中序線索二叉樹 author 菜鳥 version 2014.7.23 include include include typedef char datatype using namespace std 定義線索二叉樹的結構體 typedef struct nodethreadbitreen...