Created
June 23, 2011 14:23
-
-
Save gvinter/1042629 to your computer and use it in GitHub Desktop.
BubbleSort
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 bubble_sort(an_array){ | |
var n = an_array.length; | |
var found_inversion = true; | |
while(found_inversion){ | |
found_inversion = false; | |
for (var i=1;i<n;i++){ | |
if(an_array[i-1] > an_array[i]) { | |
found_inversion = true; | |
swap(an_array, i-1, i); | |
} | |
} | |
} | |
return an_array; | |
} | |
console.log(bubble_sort(4,5,2,3,1)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment