[理工] 資結AVL樹建立資料

作者: APE36 (PT鄉民)   2014-03-20 00:38:33
畫出產生的AVL樹,每棵樹各自獨立,對原先的樹加入/刪除資料
40
20 80
10 30 60 90
25 35 50 70
10、90沒有子樹
問題如下:
(1)加入資料26
(2)加入資料46
(3)刪除資料30
我劃出結果(1)
40
20 80
10 30 60 90
25 35 50 70
26
(2)
40
20 80
10 30 60 90
25 35 50 70
26 46
(3)
40
20 80
10 26 60 90
25 35 50 70
46
樹枝畫不出來,希望不會造成看文章的困惱,我盡量湊成對了,希望不會傷眼!!
請益一下,二元搜尋找到最大值,可以使用以下範例去證明之嗎。說明根的特性。
int left_child(int index) {return index * 2;}
int right_child(int index) {return index * 2 + 1;}
void binary_tree()
{
int tree[5 + 1];
cout << "根為" << tree[1];
cout << "根的左邊小孩是" << tree[left_child(1)];
cout << "根的右邊小孩是" << tree[right_child(1)];
}
作者: kyodaisuki (↖☆煞氣a_Kyou★↘)   2014-03-20 02:31:00
圖一 20的左右子樹不平衡 要改 圖二 80同理是一步改一次 不是一次做完
作者: A4P8T6X9 (殘廢的名偵探)   2014-03-20 07:54:00
下面那個要 complete 才有這樣的性質。
作者: hsuanyao (New Life)   2014-03-22 00:06:00
每做一步就要檢查一次唷

Links booklink

Contact Us: admin [ a t ] ucptt.com