MCPcopy
hub / github.com/wangzheng0822/algo / Insert

Method Insert

go/24_tree/BinarySearchTree.go:31–52  ·  view source on GitHub ↗
(v interface{})

Source from the content-addressed store, hash-verified

29}
30
31func (this *BST) Insert(v interface{}) bool {
32 p := this.root
33 for nil != p {
34 compareResult := this.compareFunc(v, p.data)
35 if compareResult == 0 {
36 return false
37 } else if compareResult > 0 {
38 if nil == p.right {
39 p.right = NewNode(v)
40 break
41 }
42 p = p.right
43 } else {
44 if nil == p.left {
45 p.left = NewNode(v)
46 break
47 }
48 p = p.left
49 }
50 }
51 return true
52}
53
54func (this *BST) Delete(v interface{}) bool {
55 var pp *Node = nil

Callers 10

TestBST_FindFunction · 0.95
TestBST_InsertFunction · 0.95
TestBST_MinFunction · 0.95
TestBST_MaxFunction · 0.95
TestBST_DeleteAFunction · 0.95
TestBST_DeleteCFunction · 0.95
TestBST_DeleteDFunction · 0.95
TestBST_DeleteEFunction · 0.95
TestBST_DeleteFFunction · 0.95
TestBST_DeleteGFunction · 0.95

Calls 1

NewNodeFunction · 0.85

Tested by 10

TestBST_FindFunction · 0.76
TestBST_InsertFunction · 0.76
TestBST_MinFunction · 0.76
TestBST_MaxFunction · 0.76
TestBST_DeleteAFunction · 0.76
TestBST_DeleteCFunction · 0.76
TestBST_DeleteDFunction · 0.76
TestBST_DeleteEFunction · 0.76
TestBST_DeleteFFunction · 0.76
TestBST_DeleteGFunction · 0.76