MCPcopy Create free account
hub / github.com/TheAlgorithms/Go / pushHelper

Method pushHelper

structure/tree/bstree.go:166–193  ·  view source on GitHub ↗
(x *BSNode[T], val T)

Source from the content-addressed store, hash-verified

164}
165
166func (t *BinarySearch[T]) pushHelper(x *BSNode[T], val T) {
167 y := t._NIL
168 for x != t._NIL {
169 y = x
170 switch {
171 case val < x.Key():
172 x = x.left
173 case val > x.Key():
174 x = x.right
175 default:
176 return
177 }
178 }
179
180 z := &BSNode[T]{
181 key: val,
182 left: t._NIL,
183 right: t._NIL,
184 parent: y,
185 }
186 if y == t._NIL {
187 t.Root = z
188 } else if val < y.key {
189 y.left = z
190 } else {
191 y.right = z
192 }
193}
194
195func (t *BinarySearch[T]) deleteHelper(z *BSNode[T]) {
196 switch {

Callers 1

PushMethod · 0.95

Calls 1

KeyMethod · 0.65

Tested by

no test coverage detected