function insert_sort($arr){
$count = count($arr);
for($i=
$tmp = $arr[$i];
$j = $i
while($arr[$j] > $tmp){
$arr[$j+
$arr[$j] = $tmp;
$j
}
}
return $arr;
}
//選擇排序(一維數組)
function select_sort($arr){
$count = count($arr);
for($i=
$k = $i;
for($j=$i+
if ($arr[$k] > $arr[$j])
$k = $j;
if ($k != $i){
$tmp = $arr[$i];
$arr[$i] = $arr[$k];
$arr[$k] = $tmp;
}
}
}
return $arr;
}
//冒泡排序(一維數組)
function bubble_sort($array){
$count = count($array);
if ($count <=
for($i=
for($j=$count
if ($array[$j] < $array[$j
$tmp = $array[$j];
$array[$j] = $array[$j
$array[$j
}
}
}
return $array;
}
//快速排序(一維數組)
function quick_sort($array){
if (count($array) <=
$key = $array[
$left_arr = array();
$right_arr = array();
for ($i=
if ($array[$i] <= $key) $left_arr[] = $array[$i];
else
$right_arr[] = $array[$i];
}
$left_arr = quick_sort($left_arr);
$right_arr = quick_sort($right_arr);
return array_merge($left_arr
}
From:http://tw.wingwit.com/Article/program/PHP/201311/21194.html