Closed thorehusfeldt closed 4 years ago
In the reference implementation, if a ceiling is called on a non-empty BST with an argument that is larger than the maximum element, the BST returns a null reference.
ceiling
https://github.com/kevin-wayne/algs4/blob/ae02313405283bfa82b92bdbaad00d0a88f37d3d/src/main/java/edu/princeton/cs/algs4/BST.java#L325
The documentation instead indicates that the operation should throw an exception.
(The operation does throw an exception if the BST is empty.)
A case can be made for both behaviours, but currently the implementation and documentation contradict each other.
Thanks. Updated to throw a NoSuchElementException in such cases (to match documentation and behavior of ST.java). Also updated RedBlackBST.java.
In the reference implementation, if a
ceiling
is called on a non-empty BST with an argument that is larger than the maximum element, the BST returns a null reference.https://github.com/kevin-wayne/algs4/blob/ae02313405283bfa82b92bdbaad00d0a88f37d3d/src/main/java/edu/princeton/cs/algs4/BST.java#L325
The documentation instead indicates that the operation should throw an exception.
(The operation does throw an exception if the BST is empty.)
A case can be made for both behaviours, but currently the implementation and documentation contradict each other.