feat: add LevelOrderTraverse func

This commit is contained in:
dudaodong committed 2022-03-01 11:23:33 +08:00
1 parent aa28479d11
commit 06bd407a0c
3 files changed
+47 -1

No files matched your search

+7
View File
@@ -63,6 +63,13 @@ func (t *BSTree[T]) InOrderTraverse() []T {
return inOrderTraverse(t.root)
}
// LevelOrderTraverse traverse tree node in level order
func (t *BSTree[T]) LevelOrderTraverse() []T {
traversal := make([]T, 0)
levelOrderTraverse(t.root, &traversal)
return traversal
}
// Depth returns the calculated depth of a binary saerch tree
func (t *BSTree[T]) Depth() int {
return calculateDepth(t.root, 0)