diff --git a/datastructure/tree/bstree.go b/datastructure/tree/bstree.go index 9362456..f0100f7 100644 --- a/datastructure/tree/bstree.go +++ b/datastructure/tree/bstree.go @@ -22,7 +22,7 @@ func NewBSTree[T any](rootData T) *BSTree[T] { } // 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 newNode := datastructure.NewTreeNode(data) if root == nil { diff --git a/datastructure/tree/bstree_test.go b/datastructure/tree/bstree_test.go index 626a88b..2cb2fa6 100644 --- a/datastructure/tree/bstree_test.go +++ b/datastructure/tree/bstree_test.go @@ -20,14 +20,14 @@ func (c *intComparator) Compare(v1, v2 any) int { return 0 } -func TestBSTree_Insert(t *testing.T) { +func TestBSTree_InsertNode(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.InsertNode(7, comparator) + bstree.InsertNode(5, comparator) + bstree.InsertNode(2, comparator) + bstree.InsertNode(4, comparator) bstree.Print() } @@ -38,10 +38,10 @@ func TestBSTree_PreOrderTraverse(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.InsertNode(7, comparator) + bstree.InsertNode(5, comparator) + bstree.InsertNode(2, comparator) + bstree.InsertNode(4, comparator) acturl := bstree.PreOrderTraverse() t.Log(acturl) @@ -54,10 +54,10 @@ func TestBSTree_PostOrderTraverse(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.InsertNode(7, comparator) + bstree.InsertNode(5, comparator) + bstree.InsertNode(2, comparator) + bstree.InsertNode(4, comparator) acturl := bstree.PostOrderTraverse() t.Log(acturl) @@ -70,10 +70,10 @@ func TestBSTree_InOrderTraverse(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.InsertNode(7, comparator) + bstree.InsertNode(5, comparator) + bstree.InsertNode(2, comparator) + bstree.InsertNode(4, comparator) acturl := bstree.InOrderTraverse() t.Log(acturl)