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

Method Predecessor

structure/tree/avl.go:153–160  ·  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

151// if there is no predecessor, return default value of type T and false
152// otherwise return the Key of predecessor and true
153func (avl *AVL[T]) Predecessor(key T) (T, bool) {
154 node, ok := searchTreeHelper[T](avl.Root, avl._NIL, key)
155 if !ok {
156 var dft T
157 return dft, ok
158 }
159 return predecessorHelper[T](node, avl._NIL)
160}
161
162// Successor returns the Successor of the node of Key
163// 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