Home > Backend Development > PHP Tutorial > PHP implementation of selection sorting algorithm_PHP tutorial

PHP implementation of selection sorting algorithm_PHP tutorial

WBOY
Release: 2016-07-14 10:11:26
Original
883 people have browsed it

[php]
function select_sort($arr){ 
    $len=count($arr); 
    for($i=0; $i<$len-1; $i++){ 
        $min=$i; 
        for ($j = $i+1; $j < $len; $j++) { 
            if($arr[$j]<$arr[$min]){ 
                $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<$len-1; $i++){
  $min=$i;
  for ($j = $i+1; $j < $len; $j++) {
   if($arr[$j]<$arr[$min]){
    $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);
?>

 

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/477335.htmlTechArticle[php] ?php function select_sort($arr){ $len=count($arr); for($i=0; $i$len-1; $i++){ $min=$i; for ($j = $i+1; $j $len; $j++) { if($arr[$j]$arr[$min]){ $min=$j; } } $tmp=$arr[$min];...
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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template