This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Quicksort implemented in JS by @sebastianfdez | |
* @param {number[]} nums | |
* @returns {number[]} | |
*/ | |
export function mergeSort(nums) { | |
if (nums.length <= 1) { | |
return nums; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* btree namespace. | |
* @type {BTree} | |
*/ | |
export default class BTree { | |
constructor(order) { | |
/** @type {number} */ | |
this.order = order; | |
/** | |
* Root node of the tree. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class BTreeNode { | |
constructor(isLeaf) { | |
/** | |
* @type {number[]} list of values in the node | |
*/ | |
this.values = []; | |
/** | |
* @type {boolean} is a leaf | |
*/ | |
this.leaf = isLeaf; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* btree namespace. | |
* @type {BTree} | |
*/ | |
export default class BTree { | |
... | |
/** | |
* Transfer one value from the origin to the target. | |
* @param {BTreeNode} origin | |
* @param {BTreeNode} target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class BTreeNode { | |
... | |
/** | |
* Get the immediate with more values. If there no one with extra | |
* values, return one of the immediate brothers | |
* @returns {BTreeNode} | |
*/ | |
getImmediateBrother() { | |
// Get position of node in parent children list | |
const index = this.parent.children.indexOf(this); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* btree namespace. | |
* @type {BTree} | |
*/ | |
export default class BTree { | |
constructor(order) { | |
/** @type {number} */ | |
this.order = order; | |
/** | |
* Root node of the tree. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* btree namespace. | |
* @type {BTree} | |
*/ | |
export default class BTree { | |
constructor(order) { | |
/** @type {number} */ | |
this.order = order; | |
/** | |
* Root node of the tree. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Basic Node of BTree. | |
* Keep reference to their children and values. | |
* Keep a reference to the parent and tree. | |
*/ | |
export class BTreeNode { | |
constructor(isLeaf) { | |
/** | |
* @type {number[]} list of values in the node | |
*/ |