看板 Grad-ProbAsk 關於我們 聯絡資訊
題目如下.... 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
s90413k64:解答就只是要做DFS 反正不管解答 用BFS或DFS就好了 09/09 23:22
jim055006:感謝大大...一語點醒 09/10 20:42