2011-08-16 76 views
-5

我堅持BSTree節點的深度
有沒有人有算法或代碼找到深度的BSTree節點?
感謝深度的BSTree節點(java)

+0

您能否讓您的問題更清楚?樹的深度定義爲樹的高度?你是BST AVL(平衡樹)? –

+0

另外,您的BST數據結構是否增強? –

回答

0

僞代碼:

Function Depth 
    If the right child isn't null, set left_depth to Depth(left_child), else set left_depth to 0. 
    If the left child isn't null,set right_depth to Depth(right_child), else set right_depth to 0. 
    return maximum(left_depth, right_depth) + 1; 

this發佈代碼。

+0

感謝這有助於 – Vlatko