1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-11 16:22:26 +08:00

feat: update deleteTreeNode func

This commit is contained in:
dudaodong
2022-03-01 11:13:44 +08:00
parent bf7db0ded2
commit aa28479d11
3 changed files with 44 additions and 10 deletions

View File

@@ -84,6 +84,7 @@ func insertTreeNode[T any](rootNode, newNode *datastructure.TreeNode[T], compara
}
}
// todo, delete root node failed
func deleteTreeNode[T any](node *datastructure.TreeNode[T], data T, comparator lancetconstraints.Comparator) *datastructure.TreeNode[T] {
if node == nil {
return nil
@@ -189,3 +190,14 @@ func isAllNil[T any](nodes []*datastructure.TreeNode[T]) bool {
}
return true
}
func calculateDepth[T any](node *datastructure.TreeNode[T], depth int) int {
if node == nil {
return depth
}
return max(calculateDepth(node.Left, depth+1), calculateDepth(node.Right, depth+1))
}
func max(a, b int) int {
return int(math.Max(float64(a), float64(b)))
}