Skip to content

Commit 8773672

Browse files
committed
inlined prevnext with nothing input, and edited comments to meet style.
1 parent f05f43f commit 8773672

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

src/binarytree.jl

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -169,37 +169,34 @@ maxnode(node::Nothing) = nothing
169169
function prevnext(tree::BinaryTree, k)
170170
prev, next = nothing, nothing
171171
current = root(tree)
172-
# Traverse from the root to the target node, updating candidates.
172+
# traverse from the root to the target node, updating candidates
173173
while !isnothing(current) && key(current) != k
174174
if k < key(current)
175175
# current is a potential next (successor)
176176
next = current
177177
current = left(current)
178-
else # k.key > current.key
178+
else # k > key(current)
179179
# current is a potential previous (predecessor)
180180
prev = current
181181
current = right(current)
182182
end
183183
end
184184

185-
# If the node wasn't found, return the best candidate values
185+
# if the node wasn't found, return the best candidate values
186186
if isnothing(current)
187187
return (prev, next)
188188
end
189189

190-
# Found the node with key equal to x.key.
191-
# Now, if there is a left subtree, the true previous (predecessor) is the maximum in that subtree.
190+
# if there is a left subtree, the true previous (predecessor) is the maximum in that subtree
192191
if !isnothing(left(current))
193192
prev = maxnode(left(current))
194193
end
195-
# Similarly, if there is a right subtree, the true next (successor) is the minimum in that subtree.
194+
# similarly, if there is a right subtree, the true next (successor) is the minimum in that subtree
196195
if !isnothing(right(current))
197196
next = minnode(right(current))
198197
end
199198

200199
(prev, next)
201200
end
202201

203-
function prevnext(tree::BinaryTree, k::Nothing)
204-
(nothing, nothing)
205-
end
202+
prevnext(tree::BinaryTree, k::Nothing) = (nothing, nothing)

0 commit comments

Comments
 (0)