Last active
April 13, 2017 08:41
-
-
Save keisukeYamagishi/c663c33a8be4c07bf0aa281dbff8312f to your computer and use it in GitHub Desktop.
Bubble sort logic
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
/** | |
* Created by shichimi on 2016/06/28. | |
*/ | |
var bubblesort = function busort(array){ | |
for(var sort=0;sort<array.length;sort++){ | |
for(var y=sort;y>0;y--){ | |
if(array[y-1]>array[y]){ | |
var number = array[y]; | |
array[y] = array[y-1] | |
array[y-1] = number; | |
} | |
} | |
} | |
for(var result=0;result<array.length;result++){ | |
document.write(array[result]+","); | |
} | |
} | |
var randomarray = function randum(number){ | |
var ary = []; | |
for(var create = 0; create<number; create++){ | |
var rand = Math.floor(Math.random()*100); | |
ary.unshift(rand); | |
} | |
return ary; | |
} | |
bubblesort(randomarray(10)); |
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>bubblesort</title> | |
</head> | |
<body> | |
<script src="bubblesort.js"></script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
bubble sort
opne index.html