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
class SingleLinkedList{ | |
constructor(){ | |
this.firstNode = null; | |
} | |
//Insert item at beginning of list | |
insert(data){ | |
var newNode = new Node(data); | |
newNode.nextNode = this.firstNode; |
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
class Stack{ | |
constructor(){ | |
this.head = null; | |
} | |
push(data){ | |
var newNode = new Node(data); | |
newNode.next = this.head; | |
this.head = newNode; |
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
class Queue{ | |
constructor(){ | |
this.head; | |
this.tail; | |
} | |
enqueue(data){ | |
var node = new Node(data); | |
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
class MaxHeap{ | |
constructor(){ | |
this.data = []; | |
this.position = 1; | |
} | |
insert(value){ | |
this.data[this.position] = 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
class MaxHeap{ | |
constructor(){ | |
this.data = []; | |
this.position = 1; | |
} | |
insert(value){ | |
this.data[this.position] = 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
function quicksort(input, low, high){ | |
if(low < high){ | |
var pivot = partition(input, low, high); | |
quicksort(input, low, pivot-1) | |
quicksort(input, pivot+1, high); | |
} | |
} | |
function partition(input, low, high){ | |
var pivot = input[high]; |
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(input){ | |
if(input.length === 1) | |
return input; | |
var input1 = mergesort(input.slice(0, input.length/2)); | |
var input2 = mergesort(input.slice(input.length/2)); | |
return merge(input1, input2); | |
} |
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 bubblesort(input){ | |
var n = input.length; | |
var swapped; | |
var temp; | |
do{ | |
swapped = false; | |
for(var i = 1; i < n; i++){ | |
if(input[i - 1] > input[i]){ | |
temp = input[i]; | |
input[i] = input[i-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
function insertionSort(input){ | |
var j; | |
var temp; | |
for(var i = 1; i < input.length; i++){ | |
j = i; | |
while(j > 0 && input[j-1] > input[j]){ | |
temp = input[j]; | |
input[j] = input[j-1]; | |
input[j-1] = temp; | |
j--; |
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 selectionSort(input){ | |
var temp; | |
for(var j = 0; j < input.length - 1; j++){ | |
var min = j; | |
for(var i = j+1; i < input.length; i++){ | |
if(input[i] < input[min]){ | |
min = i; | |
} | |
} | |
OlderNewer