Last active
March 5, 2019 03:55
-
-
Save wlight/4e39b54a5add09e63b3ffbcb0f9b3712 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 bubble_sort($array){ | |
$count = count($array); | |
if ($count <= 0) return false; | |
for($i=0; $i<$count; $i++){ | |
for($j=$i+1; $j<$count; $j++){ | |
if ($array[$i] > $array[$j]){ | |
$tmp = $array[$i]; | |
$array[$i] = $array[$j]; | |
$array[$j] = $tmp; | |
} | |
} | |
} | |
return $array; | |
} | |
print_r(bubble_sort([2,6,7,1,4])); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment