|
148 | 148 | # UTILITIES
|
149 | 149 | # -----------
|
150 | 150 |
|
| 151 | +""" |
| 152 | + BinaryTrees.minnode(tree) |
| 153 | +
|
| 154 | +Find the `node` with the smallest `key` in the `tree`. |
| 155 | +
|
| 156 | + BinaryTrees.minnode(node) |
| 157 | +
|
| 158 | +Find the `node` with the smallest `key` in the subtree rooted at `node`. |
| 159 | +If `nothing` is provided, `nothing` is returned. |
| 160 | +""" |
151 | 161 | minnode(tree::BinaryTree) = minnode(root(tree))
|
152 | 162 |
|
153 | 163 | function minnode(node::BinaryNode)
|
|
157 | 167 |
|
158 | 168 | minnode(node::Nothing) = nothing
|
159 | 169 |
|
| 170 | +""" |
| 171 | + BinaryTrees.maxnode(tree) |
| 172 | +
|
| 173 | +Find the `node` with the maximum `key` in the `tree`. |
| 174 | +
|
| 175 | + BinaryTrees.maxnode(node) |
| 176 | +
|
| 177 | +Find the `node` with the maximum `key` in the subtree rooted at `node`. |
| 178 | +If `nothing` is provided, `nothing` is returned. |
| 179 | +""" |
160 | 180 | maxnode(tree::BinaryTree) = maxnode(root(tree))
|
161 | 181 |
|
162 | 182 | function maxnode(node::BinaryNode)
|
|
166 | 186 |
|
167 | 187 | maxnode(node::Nothing) = nothing
|
168 | 188 |
|
| 189 | +""" |
| 190 | + BinaryTrees.prevnext(tree, k) |
| 191 | +
|
| 192 | +Returns a `tuple` of each `node` immediately before |
| 193 | +and after the `node` with `key`, `k` within `tree`. |
| 194 | +
|
| 195 | +If an adjacent `node` does not exist, `nothing` is returned in its place. |
| 196 | +If `k` is `nothing`, returns `(nothing, nothing)`. |
| 197 | +""" |
169 | 198 | function prevnext(tree::BinaryTree, k)
|
170 | 199 | prev, next = nothing, nothing
|
171 | 200 | current = root(tree)
|
|
0 commit comments