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

feat: add BSTree which is binary search tree

This commit is contained in:
dudaodong
2022-02-21 16:48:27 +08:00
parent e7ee2ed7cf
commit b2b6710a1b
4 changed files with 191 additions and 0 deletions

View File

@@ -0,0 +1,29 @@
package datastructure
import "testing"
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 TestBSTree_Insert(t *testing.T) {
bstree := NewBSTree(6)
comparator := &intComparator{}
bstree.Insert(7, comparator)
bstree.Insert(5, comparator)
bstree.Insert(2, comparator)
bstree.Insert(4, comparator)
bstree.Print()
}