[理工] [資結] Tree

看板Grad-ProbAsk作者 (jim)時間13年前 (2011/09/09 23:15), 編輯推噓1(101)
留言2則, 2人參與, 最新討論串1/1
題目如下.... Write a function which finds the integer value of the maximum integer in an unordered tree (i.e., it is NOT a binary search tree), such as the one shown (note that your function must work on ANY such tree). You may assume that all integers in the tree are non-negative. Root ↓ 3 / \ 7 5 / \ / 10 19 42 答案如下.... MAX=-1; procedure postorder(T) begin if (T is not unil) then begin inorder(T↑.Lchild); inorder(T↑.Rchild); if (T↑.Data>MAX) MAX=T↑.Data end; end 其中我比較看不懂的是line4那句是甚麼意思(我絕對沒有打錯喔...除非他印錯)... 還有他用inorder來做可是他開頭卻是postorder.. 難道是還要自己再多寫一個inorder嗎?? 最後, 我也照他的Algo.跑過一遍...可是出來的結果好奇怪 完全看不出來是不是MAX... 希望高手們幫我解惑一下... 肛溫~~ -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 223.143.61.46

09/09 23:22, , 1F
解答就只是要做DFS 反正不管解答 用BFS或DFS就好了
09/09 23:22, 1F

09/10 20:42, , 2F
感謝大大...一語點醒
09/10 20:42, 2F
文章代碼(AID): #1EQYsfQN (Grad-ProbAsk)