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

docs: add doc tree-zh-CN.md

This commit is contained in:
dudaodong
2022-06-07 14:39:32 +08:00
parent 69f8bee935
commit 6bfaba750d
2 changed files with 587 additions and 0 deletions

View File

@@ -33,6 +33,7 @@ import (
- [LevelOrderTraverse](#BSTree_LevelOrderTraverse)
- [Depth](#BSTree_Depth)
- [HasSubTree](#BSTree_HasSubTree)
- [Print](#BSTree_Print)
@@ -413,6 +414,7 @@ func main() {
bstree.Insert(4)
fmt.Println(bstree.Depth()) //4
}
```
@@ -464,4 +466,62 @@ func main() {
fmt.Println(superTree.HasSubTree(subTree)) //true
fmt.Println(subTree.HasSubTree(superTree)) //false
}
```
### <span id="BSTree_Print">Print</span>
<p>Print the structure of binary saerch tree</p>
<b>Signature:</b>
```go
func (t *BSTree[T]) Print()
```
<b>Example:</b>
```go
package main
import (
"fmt"
tree "github.com/duke-git/lancet/v2/datastructure/tree"
)
type intComparator struct{}
func (c *intComparator) Compare(v1, v2 any) int {
val1, _ := v1.(int)
val2, _ := v2.(int)
if val1 < val2 {
return -1
} else if val1 > val2 {
return 1
}
return 0
}
func main() {
bstree := tree.NewBSTree(6, &intComparator{})
bstree.Insert(7)
bstree.Insert(5)
bstree.Insert(2)
bstree.Insert(4)
fmt.Println(bstree.Print())
// 6
// / \
// / \
// / \
// / \
// 5 7
// /
// /
// 2
// \
// 4
}
```