Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
バブルソートで配列の値を昇順にソートする(JavaScript版)
/*
* バブルソートで配列の値を昇順にソートする
*
*/
var list = [8, 1, 3, 4, 9, 5],
j = 1,
i,
tmp;
for (j; j < list.length; j++) {
for (i = j; i < list.length; i++) {
if (list[i - 1] > list[i]) {
tmp = list[i];
list[i] = list[i - 1];
list[i - 1] = tmp;
}
}
}
console.log(list);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.