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

refactor: rename Insert to InsertNode

This commit is contained in:
dudaodong
2022-03-01 10:11:37 +08:00
parent 9d5db895c9
commit dd1cbf2ee3
2 changed files with 18 additions and 18 deletions

View File

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

View File

@@ -20,14 +20,14 @@ func (c *intComparator) Compare(v1, v2 any) int {
return 0 return 0
} }
func TestBSTree_Insert(t *testing.T) { func TestBSTree_InsertNode(t *testing.T) {
bstree := NewBSTree(6) bstree := NewBSTree(6)
comparator := &intComparator{} comparator := &intComparator{}
bstree.Insert(7, comparator) bstree.InsertNode(7, comparator)
bstree.Insert(5, comparator) bstree.InsertNode(5, comparator)
bstree.Insert(2, comparator) bstree.InsertNode(2, comparator)
bstree.Insert(4, comparator) bstree.InsertNode(4, comparator)
bstree.Print() bstree.Print()
} }
@@ -38,10 +38,10 @@ func TestBSTree_PreOrderTraverse(t *testing.T) {
bstree := NewBSTree(6) bstree := NewBSTree(6)
comparator := &intComparator{} comparator := &intComparator{}
bstree.Insert(7, comparator) bstree.InsertNode(7, comparator)
bstree.Insert(5, comparator) bstree.InsertNode(5, comparator)
bstree.Insert(2, comparator) bstree.InsertNode(2, comparator)
bstree.Insert(4, comparator) bstree.InsertNode(4, comparator)
acturl := bstree.PreOrderTraverse() acturl := bstree.PreOrderTraverse()
t.Log(acturl) t.Log(acturl)
@@ -54,10 +54,10 @@ func TestBSTree_PostOrderTraverse(t *testing.T) {
bstree := NewBSTree(6) bstree := NewBSTree(6)
comparator := &intComparator{} comparator := &intComparator{}
bstree.Insert(7, comparator) bstree.InsertNode(7, comparator)
bstree.Insert(5, comparator) bstree.InsertNode(5, comparator)
bstree.Insert(2, comparator) bstree.InsertNode(2, comparator)
bstree.Insert(4, comparator) bstree.InsertNode(4, comparator)
acturl := bstree.PostOrderTraverse() acturl := bstree.PostOrderTraverse()
t.Log(acturl) t.Log(acturl)
@@ -70,10 +70,10 @@ func TestBSTree_InOrderTraverse(t *testing.T) {
bstree := NewBSTree(6) bstree := NewBSTree(6)
comparator := &intComparator{} comparator := &intComparator{}
bstree.Insert(7, comparator) bstree.InsertNode(7, comparator)
bstree.Insert(5, comparator) bstree.InsertNode(5, comparator)
bstree.Insert(2, comparator) bstree.InsertNode(2, comparator)
bstree.Insert(4, comparator) bstree.InsertNode(4, comparator)
acturl := bstree.InOrderTraverse() acturl := bstree.InOrderTraverse()
t.Log(acturl) t.Log(acturl)