mirror of
https://github.com/trekhleb/javascript-algorithms.git
synced 2026-03-13 08:51:02 +08:00
Code style fixes.
This commit is contained in:
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user