1 Star 1 Fork 1

读书林 / php_arithmetic

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
selectSort.php 711 Bytes
一键复制 编辑 原始数据 按行查看 历史
读书林 提交于 2014-05-10 20:23 . 选择排序
<?php
/**
* PHP 选择排序
* Created by PhpStorm.
* User: netstan
* Date: 14-5-10
* Time: 下午3:52
*/
/**
* 选择排序
* @param $arr @需要排序的数组
*/
function select_Sort(&$arr){
$size = count($arr);
$tmp = 0;
for($i = 0; $i < $size-1; $i++){
$min_Val = $arr[$i];
$min_Index = $i;
for($j = $i+1; $j < $size; $j++){
if($min_Val > $arr[$j]){
$min_Val = $arr[$j];
$min_Index = $j;
}
}
// 交换
$tmp = $arr[$i];
$arr[$i] = $arr[$min_Index];
$arr[$min_Index] = $tmp;
}
}
$arr = array(1,2,3,0,-9,-8,-1,99,999);
select_Sort($arr);
var_dump($arr);
PHP
1
https://gitee.com/netstan/php_arithmetic.git
git@gitee.com:netstan/php_arithmetic.git
netstan
php_arithmetic
php_arithmetic
master

搜索帮助