Skip to content

Instantly share code, notes, and snippets.

@timakin
Created January 22, 2015 03:28
Show Gist options
  • Save timakin/e16f4ae84e520f1c04eb to your computer and use it in GitHub Desktop.
Save timakin/e16f4ae84e520f1c04eb to your computer and use it in GitHub Desktop.
文系が学ぶコンピューターサイエンス:第1回【概要、バブルソート実装】 ref: http://qiita.com/timakin/items/4b93017a560c109e9ca6
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>JSALGO</title>
<script src="./lib/sort.js"></script>
</head>
<body>
</body>
</html>
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