Last active
September 26, 2019 15:37
-
-
Save bz0/e0e6d00645edddd52a5c819d9d54806a to your computer and use it in GitHub Desktop.
バブルソートアルゴリズム
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
<?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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
バブルソート:
https://qiita.com/kzmk/items/30ba6fa16b3ba2fcfce4