Skip to content

Commit da7f4e8

Browse files
committed
removed test typo and added docstrings for new utility functions
1 parent c1ac4c0 commit da7f4e8

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

src/binarytree.jl

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,16 @@ end
148148
# UTILITIES
149149
# -----------
150150

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+
"""
151161
minnode(tree::BinaryTree) = minnode(root(tree))
152162

153163
function minnode(node::BinaryNode)
@@ -157,6 +167,16 @@ end
157167

158168
minnode(node::Nothing) = nothing
159169

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+
"""
160180
maxnode(tree::BinaryTree) = maxnode(root(tree))
161181

162182
function maxnode(node::BinaryNode)
@@ -166,6 +186,15 @@ end
166186

167187
maxnode(node::Nothing) = nothing
168188

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+
"""
169198
function prevnext(tree::BinaryTree, k)
170199
prev, next = nothing, nothing
171200
current = root(tree)

test/runtests.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,6 @@ const BT = BinaryTrees
261261
@inferred Nothing BT.prevnext(tree, 2)[2]
262262
@inferred BT.prevnext(tree, nothing)
263263
@inferred Nothing BT.search(tree, 2)
264-
@inferred Nothing BT.search(tree, 2)
265264
@inferred Nothing BT.search(tree, 1)
266265
@inferred Nothing BT.search(tree, 3)
267266
@inferred BT.delete!(tree, 2)

0 commit comments

Comments
 (0)