作者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://webptt.com/cn.aspx?n=bbs/C_and_CPP/M.1540997510.A.EC1.html
1F:→ djshen: search的p没initialize10/31 23:10
2F:→ djshen: 看了一下参考code 他不就写了TreeNode *current = root;10/31 23:19
3F:→ djshen: 用看的看不出来的话 debugger也告诉你95行爆炸了10/31 23:21
感谢 问题解决了
我会学着用debugger的
※ 编辑: nthulibrary (42.74.29.223), 11/01/2018 11:49:46