PHP排序算法(安插,选择,交换,冒泡,快速)

WBOY
Release: 2016-06-13 10:54:45
Original
852 people have browsed it

PHP排序算法(插入,选择,交换,冒泡,快速)

<?php //冒泡排序function BubbleSort($arr) {    // 获得数组总长度    $num = count($arr);    // 正向遍历数组    for ($i = 1; $i < $num; $i++) {        // 反向遍历        for ($j = $num - 1; $j >= $i ; $j--) {            // 相邻两个数比较            if ($arr[$j] = 0) && ($iTemp  1) {        $left = QuickSort($left);    }    // 排序后的数组    $new_arr = $left;    // 将当前数组第一个放到最后    $new_arr[] = $arr[0];    // 如果又索引有值 则对右索引排序    if ($r > 1) {        $right = QuickSort($right);    }    // 根据右索引的长度再次增加数据    for($i = 0;$i 
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template