fix(curriculum): added test using a tree that is not a binary search tree (#44775)
This commit is contained in:
@ -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--
|
# --seed--
|
||||||
|
|
||||||
## --after-user-code--
|
## --after-user-code--
|
||||||
@ -114,7 +132,7 @@ function isBinarySearchTree(tree) {
|
|||||||
function checkTree(node) {
|
function checkTree(node) {
|
||||||
if (node.left != null) {
|
if (node.left != null) {
|
||||||
const left = node.left;
|
const left = node.left;
|
||||||
if (left.value > node.value) {
|
if (left.value >= node.value) {
|
||||||
isBST = false;
|
isBST = false;
|
||||||
} else {
|
} else {
|
||||||
checkTree(left);
|
checkTree(left);
|
||||||
|
Reference in New Issue
Block a user