看板 C_and_CPP 關於我們 聯絡資訊
一個Tree的結構 找出合乎條件的第一個Node 虛擬碼如下 Node* Find (Node* cur, bool (*comp)(Node*)) { if (cur == NULL) return NULL; for each child of cur { if (comp(child)) return child; } for each child of cur { return Find (child, comp); } } 有點類似 first child next sibling 結構的 search 這樣的演算法有名字嗎? 對無特別規則的tree來說有甚麼明顯缺點嗎? -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 1.171.210.120 ※ 文章網址: http://www.ptt.cc/bbs/C_and_CPP/M.1411048487.A.58B.html
CindyLinz: 我還是把它叫 DFS.. XD 09/18 22:08
CindyLinz: 要用迴圈配 stack 實作 DFS 的時候, 有時我會寫成這種 09/18 22:08
azureblaze: 這和前面插if(comp(cur))return cur;一樣啊 09/18 22:10
azureblaze: 沒事 不太一樣 09/18 22:11
carylorrk: 我也覺得本質上還是 DFS 09/19 00:45
mabinogi805: 覺得本質還是DFS +1 09/19 00:54
cismjmgoshr: Pre-order traversal的一般版本? 09/19 02:33
LPH66: 不太像, 硬要說的話是 preorder 順序然後每個點看子節點 09/19 04:52