美文网首页
PHP-选择排序

PHP-选择排序

作者: followyounger1 | 来源:发表于2017-08-09 20:22 被阅读25次
<?php
$arr = [4,9,8,6,7,3,2,1];
function selection($str){
    $c=count($str);
    for ($i=0; $i < $c; $i++) {
    # code...
    $min = $str[$i];
    $index = $i;
    for ($j=$i+1; $j < $c; $j++) {
        # code...
    if($str[$j]<$min){
            $min = $str[$j];
            $index = $j;
        }
    }
$temp = $str[$i];
$str[$i]=$min;
$str[$index]=$temp;
}
return $str;
}
print_r(selection($arr));

 ?>

相关文章

网友评论

      本文标题:PHP-选择排序

      本文链接:https://www.haomeiwen.com/subject/epgqrxtx.html