易截截图软件、单文件、免安装、纯绿色、仅160KB

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);
}
  
?>


相关文档:

PHP安装程序制作

<?php
header("Content-type:text/html;charset=gb2312"); //看你用的是什么编码,要保持一致。
$files="config.php"; //要写入的配置文件。
if(!is_writable($files)){ //判断是否有可写的权限,linux操作系统要注意这一点,windows不必注意。
echo "<font color=red>文件不可写</font>";
......

在CENT OS上编译安装APACHE+PHP+MYSQL

 源码目录:/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 ......

fedora下php环境配置

编译安装
apache
下载apache安装
=============================
我把他安装在/usr/local/apache目录下
tar -zxvf apache文件
进入解压后的目录,配置./configure --prefix=/usr/local/apache -enable-mods-shared=all -enable-so -enable-rewrite
make
make install
然后启动/usr/local/apache/bin/apachectl sta ......

关于PHP你可能不知道的10件事

小编之前也曾报导过PHP开发人员容易忽略的几点精华,除了一些精华技术方法外,很多细微之处也是程序员
们容易忽略的,下面我们为您总结了10个关于PHP你可能不知道的事情。
  关于PHP更多内容,欢迎访问:PHP开发基础入门
  1.使用ip2long() 和long2ip()函数来把IP地址转化成整型存储到数据库里。
  这种方法把存储 ......

Month of PHP Security Summary

it is 21th of May. The Month of PHP Security
(http://www.php-security.org) is still running and we have reached a
vulnerability count of 40 vulnerabilities, which is nearly as much as we
disclosed during the whole Month of PHP Bugs in 2007. However there are
11 more days until the end of May and ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号