[問題] 二元搜尋樹刪除

看板C_and_CPP作者 (LIB)時間6年前發表 (2018/10/31 14:51), 6年前編輯推噓0(003)
留言3則, 1人參與, 6年前最新討論串1/1
開發平台(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

10/31 23:10, 6年前 , 1F
search的p沒initialize
10/31 23:10, 1F

10/31 23:19, 6年前 , 2F
看了一下參考code 他不就寫了TreeNode *current = root;
10/31 23:19, 2F

10/31 23:21, 6年前 , 3F
用看的看不出來的話 debugger也告訴你95行爆炸了
10/31 23:21, 3F
感謝 問題解決了 我會學著用debugger的 ※ 編輯: nthulibrary (42.74.29.223), 11/01/2018 11:49:46
文章代碼(AID): #1RsS66x1 (C_and_CPP)