MCPcopy Create free account
hub / github.com/careercup/ctci / insert

Function insert

go/chapter04/binarytree/binarytree.go:122–140  ·  view source on GitHub ↗

Inserts a node into the BST

(t *Tree, v int)

Source from the content-addressed store, hash-verified

120
121//Inserts a node into the BST
122func insert(t *Tree, v int) *Tree {
123 if t == nil {
124 return &Tree{nil, v, nil, t, false}
125 }
126 if t.Left == nil && t.Right == nil {
127 if v < t.Value{
128 t.Left = &Tree{nil, v, nil, t, false}
129 } else {
130 t.Right = &Tree{nil, v, nil, t, false}
131 }
132 return t
133 }
134 if v < t.Value {
135 t.Left = insert(t.Left, v)
136 return t
137 }
138 t.Right = insert(t.Right, v)
139 return t
140}
141
142func main() {
143 //t1 := New(100, 1)

Callers 1

NewFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected