Skip to content

Instantly share code, notes, and snippets.

@brianxautumn
Created April 16, 2017 19:12
Show Gist options
  • Save brianxautumn/c480a268832f16f75330ea89cd6951a4 to your computer and use it in GitHub Desktop.
Save brianxautumn/c480a268832f16f75330ea89cd6951a4 to your computer and use it in GitHub Desktop.
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];
input[i-1] = temp;
swapped = true
}
}
n--;
}while(swapped)
}
var test = [1 , 5, 8 ,10, 45, 100, -5];
bubblesort(test);
console.warn(test);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment