Code style fixes.

This commit is contained in:
Oleksii Trekhleb 2018-05-30 07:47:49 +03:00
parent 797a6f28a3
commit 8d868ae582

View File

@ -1,6 +1,9 @@
import BinarySearchTree from '../binary-search-tree/BinarySearchTree'; import BinarySearchTree from '../binary-search-tree/BinarySearchTree';
export default class AvlTree extends BinarySearchTree { export default class AvlTree extends BinarySearchTree {
/**
* @param {*} value
*/
insert(value) { insert(value) {
// Do the normal BST insert. // Do the normal BST insert.
super.insert(value); super.insert(value);
@ -13,6 +16,9 @@ export default class AvlTree extends BinarySearchTree {
} }
} }
/**
* @param {BinarySearchTreeNode} node
*/
balance(node) { balance(node) {
// If balance factor is not OK then try to balance the node. // If balance factor is not OK then try to balance the node.
if (node.balanceFactor > 1) { if (node.balanceFactor > 1) {
@ -36,6 +42,9 @@ export default class AvlTree extends BinarySearchTree {
} }
} }
/**
* @param {BinarySearchTreeNode} rootNode
*/
rotateLeftLeft(rootNode) { rotateLeftLeft(rootNode) {
// Detach left node from root node. // Detach left node from root node.
const leftNode = rootNode.left; const leftNode = rootNode.left;
@ -59,6 +68,9 @@ export default class AvlTree extends BinarySearchTree {
leftNode.setRight(rootNode); leftNode.setRight(rootNode);
} }
/**
* @param {BinarySearchTreeNode} rootNode
*/
rotateLeftRight(rootNode) { rotateLeftRight(rootNode) {
// Detach left node from rootNode since it is going to be replaced. // Detach left node from rootNode since it is going to be replaced.
const leftNode = rootNode.left; const leftNode = rootNode.left;
@ -78,6 +90,9 @@ export default class AvlTree extends BinarySearchTree {
this.rotateLeftLeft(rootNode); this.rotateLeftLeft(rootNode);
} }
/**
* @param {BinarySearchTreeNode} rootNode
*/
rotateRightLeft(rootNode) { rotateRightLeft(rootNode) {
// Detach right node from rootNode since it is going to be replaced. // Detach right node from rootNode since it is going to be replaced.
const rightNode = rootNode.right; const rightNode = rootNode.right;
@ -97,6 +112,9 @@ export default class AvlTree extends BinarySearchTree {
this.rotateRightRight(rootNode); this.rotateRightRight(rootNode);
} }
/**
* @param {BinarySearchTreeNode} rootNode
*/
rotateRightRight(rootNode) { rotateRightRight(rootNode) {
// Detach right node from root node. // Detach right node from root node.
const rightNode = rootNode.right; const rightNode = rootNode.right;