作者nthulibrary (LIB)
看板C_and_CPP
標題[問題] 二元搜尋樹刪除
時間Wed Oct 31 22:51:46 2018
開發平台(Platform): (Ex: Win10, Linux, ...)
macOS 10.14
編譯器(Ex: GCC, clang, VC++...)+目標環境(跟開發平台不同的話需列出)
g++-8
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
None
問題(Question):
我正在練習資結中BST的插入與刪除實作,本來是看著網路上的code自己打。
但是在刪除的時候會報Segmentation fault導致無法順利刪除,
於是我乾脆把網路上的code直接複製進我的程式,結果依然報segment fault,
但是網路上的code直接執行是ok的。
餵入的資料(Input):
Insert 5
Insert 4
Insert 6
Insert 3
Traverse
Insert 7
Delete 6
預期的正確結果(Expected Output):
5 4 3 6
5 4 3 7
錯誤結果(Wrong Output):
5 4 3 6
segmentation fault
程式碼(Code):(請善用置底文網頁, 記得排版,禁止使用圖檔)
我的code:
https://glot.io/snippets/f68kfp54d9
參考的code:
https://tinyurl.com/y7wto5vr
補充說明(Supplement):
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.114.129.1
※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1540997510.A.EC1.html
→ djshen: search的p沒initialize10/31 23:10
→ djshen: 看了一下參考code 他不就寫了TreeNode *current = root;10/31 23:19
→ djshen: 用看的看不出來的話 debugger也告訴你95行爆炸了10/31 23:21
感謝 問題解決了
我會學著用debugger的
※ 編輯: nthulibrary (42.74.29.223), 11/01/2018 11:49:46