Skip to content

Instantly share code, notes, and snippets.

@wlight
Last active March 5, 2019 03:55
Show Gist options
  • Save wlight/4e39b54a5add09e63b3ffbcb0f9b3712 to your computer and use it in GitHub Desktop.
Save wlight/4e39b54a5add09e63b3ffbcb0f9b3712 to your computer and use it in GitHub Desktop.
冒泡排序
<?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