@@ -169,37 +169,34 @@ maxnode(node::Nothing) = nothing
169
169
function prevnext (tree:: BinaryTree , k)
170
170
prev, next = nothing , nothing
171
171
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
173
173
while ! isnothing (current) && key (current) != k
174
174
if k < key (current)
175
175
# current is a potential next (successor)
176
176
next = current
177
177
current = left (current)
178
- else # k.key > current. key
178
+ else # k > key(current)
179
179
# current is a potential previous (predecessor)
180
180
prev = current
181
181
current = right (current)
182
182
end
183
183
end
184
184
185
- # If the node wasn't found, return the best candidate values
185
+ # if the node wasn't found, return the best candidate values
186
186
if isnothing (current)
187
187
return (prev, next)
188
188
end
189
189
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
192
191
if ! isnothing (left (current))
193
192
prev = maxnode (left (current))
194
193
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
196
195
if ! isnothing (right (current))
197
196
next = minnode (right (current))
198
197
end
199
198
200
199
(prev, next)
201
200
end
202
201
203
- function prevnext (tree:: BinaryTree , k:: Nothing )
204
- (nothing , nothing )
205
- end
202
+ prevnext (tree:: BinaryTree , k:: Nothing ) = (nothing , nothing )
0 commit comments