Created
September 2, 2013 03:04
-
-
Save shoyan/6408883 to your computer and use it in GitHub Desktop.
バブルソートで配列の値を昇順にソートする(JavaScript版)
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
/* | |
* バブルソートで配列の値を昇順にソートする | |
* | |
*/ | |
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