Skip to content

Instantly share code, notes, and snippets.

@bz0
Last active September 26, 2019 15:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bz0/e0e6d00645edddd52a5c819d9d54806a to your computer and use it in GitHub Desktop.
Save bz0/e0e6d00645edddd52a5c819d9d54806a to your computer and use it in GitHub Desktop.
バブルソートアルゴリズム
<?php
function bubbleSort($a, $n){
$flag = true;
for($i=0; $flag; $i++){
$flag = false;
for($j=$n-1; $j>=$i+1; $j--){
if ($a[$j]<$a[$j-1]){
list($a[$j], $a[$j-1]) = array($a[$j-1], $a[$j]);
$flag = true;
}
}
}
return $a;
}
$a = [10,5,7,6,3,4,8,1,9,2];
$a = bubbleSort($a, count($a));
print_r($a);
@bz0
Copy link
Author

bz0 commented Sep 26, 2019

@bz0
Copy link
Author

bz0 commented Sep 26, 2019

【Unity】ソートアルゴリズム12種を可視化してみた
https://qiita.com/r-ngtm/items/f4fa55c77459f63a5228

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment