fix(curriculum): added test using a tree that is not a binary search tree (#44775)
parent
cacc4eacd7
commit
fba519621a
|
@ -39,6 +39,24 @@ assert(
|
|||
);
|
||||
```
|
||||
|
||||
`isBinarySearchTree()` should return false when checked with a tree that is not a binary search tree.
|
||||
|
||||
```js
|
||||
assert(
|
||||
(function () {
|
||||
var test = false;
|
||||
if (typeof BinarySearchTree !== 'undefined') {
|
||||
test = new BinarySearchTree();
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
test.push(1);
|
||||
test.root.left = new Node(1);
|
||||
return isBinarySearchTree(test) == false;
|
||||
})()
|
||||
);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --after-user-code--
|
||||
|
@ -114,7 +132,7 @@ function isBinarySearchTree(tree) {
|
|||
function checkTree(node) {
|
||||
if (node.left != null) {
|
||||
const left = node.left;
|
||||
if (left.value > node.value) {
|
||||
if (left.value >= node.value) {
|
||||
isBST = false;
|
||||
} else {
|
||||
checkTree(left);
|
||||
|
|
Loading…
Reference in New Issue