MCPcopy Create free account
hub / github.com/ardanlabs/gotraining / replaceNode

Method replaceNode

topics/go/algorithms/data/tree/binary/binary.go:276–290  ·  view source on GitHub ↗

replaceNode replaces the parent’s child pointer to n with a pointer to the replacement node. parent must not be nil.

(parent, replacement *node)

Source from the content-addressed store, hash-verified

274// replaceNode replaces the parent’s child pointer to n with a pointer
275// to the replacement node. parent must not be nil.
276func (n *node) replaceNode(parent, replacement *node) error {
277 if n == nil {
278 return errors.New("replaceNode() not allowed on a nil node")
279 }
280
281 switch n {
282 case parent.left:
283 parent.left = replacement
284
285 default:
286 parent.right = replacement
287 }
288
289 return nil
290}
291
292// delete removes an element from the tree. It is an error to try
293// deleting an element that does not exist. In order to remove an

Callers 1

deleteMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected