[問題] 在 tree 的資料結構刪除 node
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
DEV C++
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
問題(Question):
在 tree 的資料結構刪除 node
餵入的資料(Input):
17 19 3 7 4 1 5 22
預期的正確結果(Expected Output):
想要刪除 4 這個資料
錯誤結果(Wrong Output):
return pointer 時發生錯誤, 無法得到答案
程式碼(Code):(請善用置底文網頁, 記得排版)
http://codepad.org/ND5SF3lE
補充說明(Supplement):
在 maketree, pretrav(preorder), binary_search 沒有問題
在 130 行 printf("p->info=%d p->father->info=%d\n", p->info, p->father->info);
可以得到想要找到的node, 接下來想要 return node 的 address,來刪除這個node
可是卻發現 return address 跟 接收到的不同導致錯誤
也就是從 142 行
t = (NODEPTR) binary_search(p,x);//這個函數會呼叫到131 行的
//printf("p=%x\n",p);然後 return p 給 t
printf("t=%x\n",t);
發現 p 跟 t 所指到的 address 不同導致錯誤,不知道這樣回傳 p 問題錯在哪裡?
謝謝
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 163.29.111.200
※ 編輯: jovi01 來自: 163.29.111.200 (11/13 11:38)
※ 編輯: jovi01 來自: 163.29.111.200 (11/13 11:39)
※ 編輯: jovi01 來自: 163.29.111.200 (11/13 11:46)
→
11/13 11:46, , 1F
11/13 11:46, 1F
→
11/13 11:49, , 2F
11/13 11:49, 2F
※ 編輯: jovi01 來自: 163.29.111.200 (11/13 11:50)
→
11/13 12:20, , 3F
11/13 12:20, 3F
→
11/13 12:22, , 4F
11/13 12:22, 4F
→
11/13 12:25, , 5F
11/13 12:25, 5F
→
11/13 12:28, , 6F
11/13 12:28, 6F
→
11/13 12:29, , 7F
11/13 12:29, 7F
→
11/13 13:22, , 8F
11/13 13:22, 8F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章