線索二叉樹

2022-03-30 06:26:21 字數 680 閱讀 6265

在嚴蔚敏的《資料結構》一書中,所使用的**存在一些小問題。原版**就不附上了,主要問題是:

1.inthreading函式的引數,應該攜帶pre,這應該是比較嚴重的問題。如果沒有攜帶pre,則對pre的修改只是在呼叫的函式中的區域性變數的值的修改,沒有影響到原來的pre的值。

2.在條件語句中,將命中概率高的語句放在前面,會提高**效率。但嚴的演算法中在inorderthreading演算法中,將t為null時放在了前面。

3.inorderthreading中,只有t為null時,執行thrt->rchild = thrt才有意義。而在t不為null時,要執行thrt->rchild = pre,即使開始執行了thrt->rchild = thrt,也會被覆蓋掉,所以把thrt->rchild = thrt句移到了else分句中。

原始碼列印

?status inorderthreading(bitree thrt, bitree t)  

else

}  原始碼列印

?void

intreading(bitree p, bitree pre)  

if(!pre->rchild)  

pre = p;  

inthreading(p->rchild, pre);  

}  }  

歡迎討論、批評與指正!

alex zhong

線索二叉樹

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