Skip to content

Commit

Permalink
Update BinarySearchTree.js
Browse files Browse the repository at this point in the history
  • Loading branch information
JaapvanEkris authored Nov 28, 2023
1 parent 33923db commit b64d7b7
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions app/engine/utils/BinarySearchTree.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,24 @@ function createLabelledBinarySearchTree () {
function push (label, value) {
if (tree === null) {
tree = newNode(label, value)
} else {
pushInTree(tree, label, value)
}
}

function pushInTree (currentTree, label, value) {
if (currentTree === null) {
currentTree = newNode(label, value)
} else {
// We encounter a filled node
if (currentTree.value >= value) {
// value <= currentTree.value, so we need the value to the left branch
pushInTree (currentTree.leftNode, label, value)

Check failure on line 27 in app/engine/utils/BinarySearchTree.js

View workflow job for this annotation

GitHub Actions / build (14.x)

Unexpected whitespace between function name and paren

Check failure on line 27 in app/engine/utils/BinarySearchTree.js

View workflow job for this annotation

GitHub Actions / build (16.x)

Unexpected whitespace between function name and paren
} else {
// currentTree.value < value, so we need to add the value to the right branch
pushInTree (currentTree.rightNode, label, value)

Check failure on line 30 in app/engine/utils/BinarySearchTree.js

View workflow job for this annotation

GitHub Actions / build (14.x)

Unexpected whitespace between function name and paren

Check failure on line 30 in app/engine/utils/BinarySearchTree.js

View workflow job for this annotation

GitHub Actions / build (16.x)

Unexpected whitespace between function name and paren
}
currentTree.numberOfLeafsAndNodes = currentTree.numberOfLeafsAndNodes + 1
}
}

Expand Down

0 comments on commit b64d7b7

Please sign in to comment.