Created
January 22, 2015 03:28
-
-
Save timakin/e16f4ae84e520f1c04eb to your computer and use it in GitHub Desktop.
文系が学ぶコンピューターサイエンス:第1回【概要、バブルソート実装】 ref: http://qiita.com/timakin/items/4b93017a560c109e9ca6
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>JSALGO</title> | |
<script src="./lib/sort.js"></script> | |
</head> | |
<body> | |
</body> | |
</html> |
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 sortTarget = function () { | |
var array = new Array(); | |
for (var i = 0; i < 100; i++) { | |
array.push(Math.random()*1000); | |
}; | |
return array; | |
} | |
function Sort() {} | |
Sort.prototype = { | |
bubble: function (sort) { | |
do { | |
var flag = 0; | |
for (var i = 0; i < sort.length; i++) { | |
if (sort[i] > sort[i+1]) { | |
flag = 1 | |
j = sort[i]; | |
sort[i] = sort[i+1]; | |
sort[i+1] = j; | |
} | |
}; | |
}while(flag); | |
return sort; | |
} | |
} | |
var sort = new Sort(); | |
console.log(sort.bubble(sortTarget())); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment