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

Method Predecessor

structure/tree/bstree.go:145–152  ·  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

143// if there is no predecessor, return default value of type T and false
144// otherwise return the Key of predecessor and true
145func (t *BinarySearch[T]) Predecessor(key T) (T, bool) {
146 node, ok := searchTreeHelper[T](t.Root, t._NIL, key)
147 if !ok {
148 var dft T
149 return dft, ok
150 }
151 return predecessorHelper[T](node, t._NIL)
152}
153
154// Successor returns the Successor of the node of Key
155// 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