Code style fixes.

This commit is contained in:
Oleksii Trekhleb
2018-05-30 08:00:25 +03:00
parent 8d868ae582
commit fcc546347d
4 changed files with 39 additions and 9 deletions

View File

@@ -3,14 +3,15 @@ import Comparator from '../../../utils/comparator/Comparator';
export default class BinarySearchTreeNode extends BinaryTreeNode {
/**
* @param {*} value
* @param {BinaryTreeNode} parent
* @param {function} compareFunction
* @param {*} [value]
* @param {BinaryTreeNode} [parent]
* @param {function} [compareFunction]
*/
constructor(value = null, parent = null, compareFunction = undefined) {
super(value, parent);
// This comparator is used to compare node values with each other.
this.compareFunction = compareFunction;
this.nodeValueComparator = new Comparator(compareFunction);
}
@@ -29,14 +30,14 @@ export default class BinarySearchTreeNode extends BinaryTreeNode {
if (this.left) {
this.left.insert(value);
} else {
this.setLeft(new BinarySearchTreeNode(value));
this.setLeft(new BinarySearchTreeNode(value, null, this.compareFunction));
}
} else if (this.nodeValueComparator.greaterThan(value, this.value)) {
// Insert to the right.
if (this.right) {
this.right.insert(value);
} else {
this.setRight(new BinarySearchTreeNode(value));
this.setRight(new BinarySearchTreeNode(value, null, this.compareFunction));
}
}