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
function Node(value){ | |
this.value = value | |
this.left = null; | |
this.right = null; | |
} | |
Node.prototype.toString = function() { | |
return this.value; | |
} |
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
const swap = (array, firstItemIndex, lastItemIndex) => { | |
const temp = array[firstItemIndex]; | |
array[firstItemIndex] = array[lastItemIndex]; | |
array[lastItemIndex] = temp; | |
} | |
const heapify = (heap, i, max) => { | |
let index, leftChild, righChild; |
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
function mergeSort (array= []) { | |
if (array.length == 1) return array | |
const middle = Math.floor(array.length / 2) | |
const leftHalf = array.slice(0, middle) | |
const rightHalf = array.slice(middle) | |
return mergeHalves( | |
mergeSort(leftHalf), |
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
function swapNumbers(items, leftIndex, rightIndex){ | |
const temp = items[leftIndex]; | |
items[leftIndex] = items[rightIndex]; | |
items[rightIndex] = temp; | |
} | |
function insertionSort(array = []) { | |
for(let i = 0; i < array.length; i++) { | |
let currentIndex = i | |
while(currentIndex > 0 && array[currentIndex] < array[currentIndex - 1]) { |
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
const items = [5,3,7,6,2,9]; | |
function swapNumbers(items, leftIndex, rightIndex){ | |
const temp = items[leftIndex]; | |
items[leftIndex] = items[rightIndex]; | |
items[rightIndex] = temp; | |
} | |
function partition(items, left, right) { | |
const pivotNumber = items[Math.floor((right + left) / 2)] | |
while (left <= right) { |
NewerOlder