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

refactor: change function name

This commit is contained in:
dudaodong
2022-06-07 13:48:32 +08:00
parent 6f17ba9116
commit 07d04a9cd0
2 changed files with 41 additions and 41 deletions

View File

@@ -24,7 +24,7 @@ func NewBSTree[T any](rootData T, comparator lancetconstraints.Comparator) *BSTr
} }
// InsertNode insert data into BSTree // InsertNode insert data into BSTree
func (t *BSTree[T]) InsertNode(data T) { func (t *BSTree[T]) Insert(data T) {
root := t.root root := t.root
newNode := datastructure.NewTreeNode(data) newNode := datastructure.NewTreeNode(data)
if root == nil { if root == nil {
@@ -35,7 +35,7 @@ func (t *BSTree[T]) InsertNode(data T) {
} }
// DeletetNode delete data into BSTree // DeletetNode delete data into BSTree
func (t *BSTree[T]) DeletetNode(data T) { func (t *BSTree[T]) Delete(data T) {
deleteTreeNode(t.root, data, t.comparator) deleteTreeNode(t.root, data, t.comparator)
} }

View File

@@ -20,13 +20,13 @@ func (c *intComparator) Compare(v1, v2 any) int {
return 0 return 0
} }
func TestBSTree_InsertNode(t *testing.T) { func TestBSTree_Insert(t *testing.T) {
bstree := NewBSTree(6, &intComparator{}) bstree := NewBSTree(6, &intComparator{})
bstree.InsertNode(7) bstree.Insert(7)
bstree.InsertNode(5) bstree.Insert(5)
bstree.InsertNode(2) bstree.Insert(2)
bstree.InsertNode(4) bstree.Insert(4)
bstree.Print() bstree.Print()
} }
@@ -36,10 +36,10 @@ func TestBSTree_PreOrderTraverse(t *testing.T) {
bstree := NewBSTree(6, &intComparator{}) bstree := NewBSTree(6, &intComparator{})
bstree.InsertNode(7) bstree.Insert(7)
bstree.InsertNode(5) bstree.Insert(5)
bstree.InsertNode(2) bstree.Insert(2)
bstree.InsertNode(4) bstree.Insert(4)
acturl := bstree.PreOrderTraverse() acturl := bstree.PreOrderTraverse()
t.Log(acturl) t.Log(acturl)
@@ -51,10 +51,10 @@ func TestBSTree_PostOrderTraverse(t *testing.T) {
bstree := NewBSTree(6, &intComparator{}) bstree := NewBSTree(6, &intComparator{})
bstree.InsertNode(7) bstree.Insert(7)
bstree.InsertNode(5) bstree.Insert(5)
bstree.InsertNode(2) bstree.Insert(2)
bstree.InsertNode(4) bstree.Insert(4)
acturl := bstree.PostOrderTraverse() acturl := bstree.PostOrderTraverse()
t.Log(acturl) t.Log(acturl)
@@ -66,10 +66,10 @@ func TestBSTree_InOrderTraverse(t *testing.T) {
bstree := NewBSTree(6, &intComparator{}) bstree := NewBSTree(6, &intComparator{})
bstree.InsertNode(7) bstree.Insert(7)
bstree.InsertNode(5) bstree.Insert(5)
bstree.InsertNode(2) bstree.Insert(2)
bstree.InsertNode(4) bstree.Insert(4)
acturl := bstree.InOrderTraverse() acturl := bstree.InOrderTraverse()
t.Log(acturl) t.Log(acturl)
@@ -81,10 +81,10 @@ func TestBSTree_LevelOrderTraverse(t *testing.T) {
bstree := NewBSTree(6, &intComparator{}) bstree := NewBSTree(6, &intComparator{})
bstree.InsertNode(7) bstree.Insert(7)
bstree.InsertNode(5) bstree.Insert(5)
bstree.InsertNode(2) bstree.Insert(2)
bstree.InsertNode(4) bstree.Insert(4)
bstree.Print() bstree.Print()
@@ -93,19 +93,19 @@ func TestBSTree_LevelOrderTraverse(t *testing.T) {
assert.Equal([]int{6, 5, 7, 2, 4}, acturl) assert.Equal([]int{6, 5, 7, 2, 4}, acturl)
} }
func TestBSTree_DeletetNode(t *testing.T) { func TestBSTree_Delete(t *testing.T) {
assert := internal.NewAssert(t, "TestBSTree_DeletetNode") assert := internal.NewAssert(t, "TestBSTree_Delete")
bstree := NewBSTree(6, &intComparator{}) bstree := NewBSTree(6, &intComparator{})
bstree.InsertNode(7) bstree.Insert(7)
bstree.InsertNode(5) bstree.Insert(5)
bstree.InsertNode(2) bstree.Insert(2)
bstree.InsertNode(4) bstree.Insert(4)
bstree.Print() bstree.Print()
bstree.DeletetNode(4) bstree.Delete(4)
bstree.Print() bstree.Print()
acturl1 := bstree.InOrderTraverse() acturl1 := bstree.InOrderTraverse()
t.Log(acturl1) t.Log(acturl1)
@@ -124,10 +124,10 @@ func TestBSTree_Depth(t *testing.T) {
bstree := NewBSTree(6, &intComparator{}) bstree := NewBSTree(6, &intComparator{})
bstree.InsertNode(7) bstree.Insert(7)
bstree.InsertNode(5) bstree.Insert(5)
bstree.InsertNode(2) bstree.Insert(2)
bstree.InsertNode(4) bstree.Insert(4)
bstree.Print() bstree.Print()
@@ -138,17 +138,17 @@ func TestBSTree_IsSubTree(t *testing.T) {
assert := internal.NewAssert(t, "TestBSTree_IsSubTree") assert := internal.NewAssert(t, "TestBSTree_IsSubTree")
superTree := NewBSTree(8, &intComparator{}) superTree := NewBSTree(8, &intComparator{})
superTree.InsertNode(4) superTree.Insert(4)
superTree.InsertNode(5) superTree.Insert(5)
superTree.InsertNode(6) superTree.Insert(6)
superTree.InsertNode(9) superTree.Insert(9)
superTree.InsertNode(4) superTree.Insert(4)
superTree.Print() superTree.Print()
subTree := NewBSTree(5, &intComparator{}) subTree := NewBSTree(5, &intComparator{})
subTree.InsertNode(4) subTree.Insert(4)
subTree.InsertNode(6) subTree.Insert(6)
subTree.Print() subTree.Print()