PHP算法---选择排序

/**  
* 选择排序 
* 
* @access public 
* @param mixed $arr 随机数组
* @return array 排序完成的数组
*/
function selectionSort($arr){
	$time_start = msectime();
	for ($i=0; $i < count($arr) ; $i++) {
		$minIndex = $i;
		for ($j=$i+1; $j < count($arr); $j++) { 
			if($arr[$j]<$arr[$minIndex]){
				$temp = $arr[$minIndex];
				$arr[$minIndex] = $arr[$j];
				$arr[$j] = $temp;
			}
		}
	}
	$time_end = msectime();
	var_dump($time_end-$time_start);
	return $arr;
}

猜你喜欢

转载自blog.csdn.net/qq_39940866/article/details/80567390
今日推荐