快速排序
来源:互联网 发布:golang smtp.sendmail 编辑:程序博客网 时间:2024/06/16 22:58
<?php// 快速排序// 时间复杂度:O(nlog2n)function __quickSort(&$arr, $p, $q){$low = $p;$high = $q;$base_value = $arr[$low]; //基准值/*while(true) {while ($low < $high && $base_value <= $arr[$high])$high--;if($low >= $high) break;$arr[$low++] = $arr[$high];while ($low < $high && $arr[$low] <= $base_value)$low++;if($low >= $high) break;$arr[$high--] = $arr[$low];}*/while($low < $high) {// 越过不小于基准值的数据while($arr[$high] >= $base_value && $high > $low)$high--;if($low < $high) {$arr[$low++] = $arr[$high];// 越过小于基准值的数据while($arr[$low] <= $base_value && $low < $high)$low++;if($low < $high)$arr[$high--] = $arr[$low];}}$arr[$low] = $base_value;if($p < $low - 1) __quickSort($arr, $p, $low - 1);if($q > $high + 1) __quickSort($arr, $high + 1, $q);}function quickSort(&$arr) {__quickSort($arr, 0, count($arr) - 1);}
0 0
- 快速排序
- 快速排序
- 快速排序
- 快速排序!
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- APUE-第五章学习-标准I/O库-习题
- 检测点11.4
- 闭包
- 字符串压缩
- 面试题5:从尾到头打印链表
- 快速排序
- 取出map集合中的值
- vue克隆v2ex网站随记
- JS异步
- 实现音乐播放器的代码(html5+css3+jquery)
- Codeforce - 712 -C. Memory and De-Evolution
- jQuery中width(),innerWidth(),outerWidth(),outerWidth(true)
- IDEA 2016.1 Maven SpringMVC学习教程_log日志的生成(三)
- Nodejs,express博客搭建