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

Method Predecessor

structure/tree/rbtree.go:154–161  ·  view source on GitHub ↗

Predecessor returns the Predecessor of the node of Key if there is no predecessor, return default value of type T and false otherwise return the Key of predecessor and true

(key T)

Source from the content-addressed store, hash-verified

152// if there is no predecessor, return default value of type T and false
153// otherwise return the Key of predecessor and true
154func (t *RB[T]) Predecessor(key T) (T, bool) {
155 node, ok := searchTreeHelper[T](t.Root, t._NIL, key)
156 if !ok {
157 var dft T
158 return dft, ok
159 }
160 return predecessorHelper[T](node, t._NIL)
161}
162
163// Successor returns the Successor of the node of Key
164// if there is no successor, return default value of type T and false

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected