<?php
date_default_timezone_set('Asia/Shanghai');
function selectSort($array){
$count= count($array);
for ($i=0; $i< $count-1;$i++){
$minIndex =$i;
for ($j=$i+1;$j<$count;$j++){
$minIndex = $array[$minIndex]<$array[$j] ? $minIndex : $j;
}
$temp = $array[$i];
$array[$i] = $array[$minIndex];
$array[$minIndex] =$temp;
}
return $array;
}
$start = microtime(true);
$tempArray = [3, 4, 2, 1, 5, 6, 7, 8, 30, 50, 1, 33, 24, 5, 7, 0];
$resArray = selectSort($tempArray);
$end = microtime(true);
var_dump((($end-$start)*1000).'ms');
排序算法-选择排序
于 2022-01-09 16:50:55 首次发布