PHP 排序算法解析
<?
//插入排序(一维数组)
function insert_sort($arr){
$count = count($arr);
for($i=1; $i<$count; $i++){
$tmp = $arr[$i];
$j = $i - 1;
while($arr[$j] > $tmp){
$arr[$j+1] = $arr[$j];
$arr[$j] = $tmp;
$j--;
}
}
return $arr;
}
//选择排序(一维数组)
function select_sort($arr){
$count = count($arr);
for($i=0; $i<$count; $i++){
$k = $i;
for($j=$i+1; $j<$count; $j++){
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 <= 0) return false;
for($i=0; $i<$count; $i++){
for($j=$count-1; $j>$i; $j--){
if ($array[$j] < $array[$j-1]){
$tmp = $array[$j];
$array[$j] = $array[$j-1];
$array[$j-1] = $tmp;
}
}
}
return $array;
}
//快速排序(一维数组)
function quick_sort($array){
if (count($array) <= 1) return $array;
$key = $array[0];
$left_arr = array();
$right_arr = array();
for ($i=1; $i<count($array); $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, array($key), $right_arr);
}
?>
相关文档:
不知不觉,5月过了大半了,想保持每个月至少给 Blog 添加一些新鲜的文章,也随便给自己的 career 轨迹做一个记录,于是提笔,呵呵~ 今天要介绍一下石头最新的作品 Hush Framework,这个框架是我这两个月的心血之作,本人还是比较满意的,以下会给大家介绍一些这个东东的亮点。这个作品的本意是为公司日后的应用开发提供一个 ......
插入代码
<?
$action=$_GET['action'];
switch($action){
//添加记录
case"add";
$mail = trim(htmlspecialchars($_POST["mail"]));
$username = trim(htmlspecialchars($_POST["username"]));
$tel = trim(htmlspecialchars($_POST["tel"]));
$fax = trim(htmlspecialchars($_POST["fax"]));
$c ......
源码目录:/usr/local/src/
应用目录:/usr/local/app/
一、MYSQL安装。
1.下载MSYQL源码:
http://www.mysql.com/downloads/mysql/
最近版本是 mysql-5.1.47.tar.gz
2.上传到服务器目录/usr/local/src/
cd /usr/local/src/
tar zxvf mysql-5.1.47.tar.gz
cd mysql-5.1.47
./configure --prefi ......
标题有点长,其实就是用来向https服务器post数据
function curlPost($url, $data, $timeout = 30)
{
$ssl = substr($url, 0, 8) == "https://" ? TRUE : FALSE;
$ch = curl_init();
$opt = array(
CURLOPT_URL => $url,
CURLOPT_POST => 1,
CURLOPT_ ......