Skip to content

Instantly share code, notes, and snippets.

View brianxautumn's full-sized avatar

Brian brianxautumn

View GitHub Profile
class SingleLinkedList{
constructor(){
this.firstNode = null;
}
//Insert item at beginning of list
insert(data){
var newNode = new Node(data);
newNode.nextNode = this.firstNode;
@brianxautumn
brianxautumn / Stack in JavaScript.js
Created April 15, 2017 18:21
Stack in JavaScript.js
class Stack{
constructor(){
this.head = null;
}
push(data){
var newNode = new Node(data);
newNode.next = this.head;
this.head = newNode;
@brianxautumn
brianxautumn / Queue With Single Linked List.js
Created April 15, 2017 21:21
Queue With Single Linked List
class Queue{
constructor(){
this.head;
this.tail;
}
enqueue(data){
var node = new Node(data);
class MaxHeap{
constructor(){
this.data = [];
this.position = 1;
}
insert(value){
this.data[this.position] = value;
class MaxHeap{
constructor(){
this.data = [];
this.position = 1;
}
insert(value){
this.data[this.position] = value;
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];
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);
}
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];
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--;
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;
}
}