Home > php教程 > php手册 > 选择排序算法的PHP实现

选择排序算法的PHP实现

WBOY
Release: 2016-06-13 10:57:24
Original
1551 people have browsed it

[php]
function select_sort($arr){ 
    $len=count($arr); 
    for($i=0; $i         $min=$i; 
        for ($j = $i+1; $j             if($arr[$j]                 $min=$j; 
            } 
        } 
        $tmp=$arr[$min]; 
        $arr[$min]=$arr[$i]; 
        $arr[$i]=$tmp; 
    } 
    return $arr; 

$arr=array(4,34,64,20,39);SelectSort($arr);print_r($arr); 
?> 

function select_sort($arr){
 $len=count($arr);
 for($i=0; $i   $min=$i;
  for ($j = $i+1; $j    if($arr[$j]     $min=$j;
   }
  }
  $tmp=$arr[$min];
  $arr[$min]=$arr[$i];
  $arr[$i]=$tmp;
 }
 return $arr;
}
$arr=array(4,34,64,20,39);SelectSort($arr);print_r($arr);
?>

 

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template