Created
April 16, 2017 19:12
-
-
Save brianxautumn/c480a268832f16f75330ea89cd6951a4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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]; | |
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