fix(curriculum): added test using a tree that is not a binary search tree (#44775)

pull/44889/head
Matt 2022-01-24 21:33:03 +02:00 committed by GitHub
parent cacc4eacd7
commit fba519621a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 19 additions and 1 deletions

View File

@ -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);