yeah

搜索

计数器

62789

链接

PHP排序算法(插入排序)
jQuery 1.4 发布:你必须知道的15个新特征

PHP排序算法(选择排序)

yeah posted @ Jan 13, 2010 06:18:38 AM in 教程 , 6061 阅读
(1)说明:
“选择排序法”(Selection Sort)是从排序的元素中选出最小的一个元素,然后和第一个元素交换。然后从剩下的元素中选出最小的元素和第二个元素交换,重复这种处理的方法,直到最后一个元素为止。
(2)算法:
$arr  = array(1, 4, 2, 3, 6);
$arrSize = count($arr);
for($i = 0; $i < $arrSize - 1; $i ) {
    for($j = $i 1; $i < $arrSize; $i ) {
        if($j < $i) {
            $tmp = $arr[$j];
            $arr[$j] = $arr[$i];
            $arr[$i] = $tmp;
        }
    }
}
(3)运行效率
第一层循环需要运行n-1次,n是全部排序元素的个数,第二层循环根据序为n-1, n-2, n-3,......,1,0,总计为n(n-1)/2次,可以得到其运行效率为O(n平方)
celeb networth 说:
Mar 23, 2022 11:39:53 PM

It's a good chance to know more about these stories, very interesting and meaningful. And please take a look at this site, where I find the all the information I need about celeb networth post


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter