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

Method deleteHelper

structure/tree/bstree.go:195–213  ·  view source on GitHub ↗
(z *BSNode[T])

Source from the content-addressed store, hash-verified

193}
194
195func (t *BinarySearch[T]) deleteHelper(z *BSNode[T]) {
196 switch {
197 case z.left == t._NIL:
198 t.transplant(z, z.right)
199 case z.right == t._NIL:
200 t.transplant(z, z.left)
201 default:
202 y := minimum[T](z.right, t._NIL).(*BSNode[T])
203 if y.parent != z {
204 t.transplant(y, y.right)
205 y.right = z.right
206 y.right.parent = y
207 }
208
209 t.transplant(z, y)
210 y.left = z.left
211 y.left.parent = y
212 }
213}
214
215func (t *BinarySearch[T]) transplant(u, v *BSNode[T]) {
216 switch {

Callers 1

DeleteMethod · 0.95

Calls 1

transplantMethod · 0.95

Tested by

no test coverage detected