Skip to content

Instantly share code, notes, and snippets.

@richard-to
Created February 17, 2014 09:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save richard-to/9047119 to your computer and use it in GitHub Desktop.
Save richard-to/9047119 to your computer and use it in GitHub Desktop.
var bubbleSort = function(list) {
var n = list.length;
var swapped = false;
var i = 0;
var temp = 0;
do {
swapped = false;
for (i = 1; i < n - 1; ++i) {
if (list[i - 1] > list[i]) {
temp = list[i];
list[i] = list[i - 1];
list[i - 1] = temp;
swapped = true;
}
}
--n;
} while (swapped);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment