mirror of
https://github.com/trekhleb/javascript-algorithms.git
synced 2026-03-13 08:51:02 +08:00
Upgrade packages.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import DoublyLinkedListNode from './DoublyLinkedListNode';
|
||||
import Comparator from './../../utils/comparator/Comparator';
|
||||
import Comparator from '../../utils/comparator/Comparator';
|
||||
|
||||
export default class DoublyLinkedList {
|
||||
/**
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import DoublyLinkedListNode from './../DoublyLinkedListNode';
|
||||
import DoublyLinkedListNode from '../DoublyLinkedListNode';
|
||||
|
||||
describe('DoublyLinkedListNode', () => {
|
||||
it('should create list node with value', () => {
|
||||
|
||||
@@ -164,10 +164,10 @@ export default class MinHeap {
|
||||
// If there is no parent or parent is less then node to delete then heapify down.
|
||||
// Otherwise heapify up.
|
||||
if (
|
||||
leftChild !== null &&
|
||||
(
|
||||
parentItem === null ||
|
||||
this.compare.lessThan(parentItem, this.heapContainer[indexToRemove])
|
||||
leftChild !== null
|
||||
&& (
|
||||
parentItem === null
|
||||
|| this.compare.lessThan(parentItem, this.heapContainer[indexToRemove])
|
||||
)
|
||||
) {
|
||||
this.heapifyDown(indexToRemove);
|
||||
@@ -208,8 +208,8 @@ export default class MinHeap {
|
||||
let currentIndex = customStartIndex || this.heapContainer.length - 1;
|
||||
|
||||
while (
|
||||
this.hasParent(currentIndex) &&
|
||||
this.compare.lessThan(this.heapContainer[currentIndex], this.parent(currentIndex))
|
||||
this.hasParent(currentIndex)
|
||||
&& this.compare.lessThan(this.heapContainer[currentIndex], this.parent(currentIndex))
|
||||
) {
|
||||
this.swap(currentIndex, this.getParentIndex(currentIndex));
|
||||
currentIndex = this.getParentIndex(currentIndex);
|
||||
@@ -227,8 +227,8 @@ export default class MinHeap {
|
||||
|
||||
while (this.hasLeftChild(currentIndex)) {
|
||||
if (
|
||||
this.hasRightChild(currentIndex) &&
|
||||
this.compare.lessThan(this.rightChild(currentIndex), this.leftChild(currentIndex))
|
||||
this.hasRightChild(currentIndex)
|
||||
&& this.compare.lessThan(this.rightChild(currentIndex), this.leftChild(currentIndex))
|
||||
) {
|
||||
nextIndex = this.getRightChildIndex(currentIndex);
|
||||
} else {
|
||||
|
||||
@@ -35,7 +35,9 @@ export default class BinarySearchTreeNode extends BinaryTreeNode {
|
||||
this.setLeft(newNode);
|
||||
|
||||
return newNode;
|
||||
} else if (this.nodeValueComparator.greaterThan(value, this.value)) {
|
||||
}
|
||||
|
||||
if (this.nodeValueComparator.greaterThan(value, this.value)) {
|
||||
// Insert to the right.
|
||||
if (this.right) {
|
||||
return this.right.insert(value);
|
||||
@@ -63,7 +65,9 @@ export default class BinarySearchTreeNode extends BinaryTreeNode {
|
||||
if (this.nodeValueComparator.lessThan(value, this.value) && this.left) {
|
||||
// Check left nodes.
|
||||
return this.left.find(value);
|
||||
} else if (this.nodeValueComparator.greaterThan(value, this.value) && this.right) {
|
||||
}
|
||||
|
||||
if (this.nodeValueComparator.greaterThan(value, this.value) && this.right) {
|
||||
// Check right nodes.
|
||||
return this.right.find(value);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user