1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-12 16:52:29 +08:00

test: add unit test TestBSTree_IsSubTree

This commit is contained in:
dudaodong
2022-04-27 11:36:51 +08:00
parent 0d48778886
commit 61c7012e17
3 changed files with 14 additions and 16 deletions

View File

@@ -77,7 +77,7 @@ func (t *BSTree[T]) Depth() int {
return calculateDepth(t.root, 0)
}
// IsSubTree checks if the tree `t`` has `subTree` or not
// IsSubTree checks if the tree `t` has `subTree` or not
func (t *BSTree[T]) HasSubTree(subTree *BSTree[T]) bool {
return hasSubTree(t.root, subTree.root, t.comparator)
}
@@ -90,11 +90,9 @@ func hasSubTree[T any](superTreeRoot, subTreeRoot *datastructure.TreeNode[T],
if comparator.Compare(superTreeRoot.Value, subTreeRoot.Value) == 0 {
res = isSubTree(superTreeRoot, subTreeRoot, comparator)
}
if !res {
res = hasSubTree(superTreeRoot.Left, subTreeRoot, comparator)
}
if !res {
res = hasSubTree(superTreeRoot.Right, subTreeRoot, comparator)
}