php的一些简单算法程序(冒泡、快速等),php算法程序冒泡_PHP教程

WBOY
發布: 2016-07-12 09:07:08
原創
842 人瀏覽過

php的一些简单算法程序(冒泡、快速等),php算法程序冒泡

<span>function</span> buttle_sort(<span>$array</span><span>) {
        </span><span>$len</span>=<span>count</span>(<span>$array</span><span>);
        </span><span>if</span>(<span>$len</span><2<span>){
            </span><span>return</span> <span>$array</span><span>;
        }
        </span><span>for</span>(<span>$i</span>=0;<span>$i</span><<span>$len</span>;<span>$i</span>++<span>){
            </span><span>$flag</span> = <span>false</span>;<span>//</span><span>本趟排序开始前,交换标志应为假</span>
            <span>for</span>(<span>$j</span>=<span>$len</span>-1;<span>$j</span>><span>$i</span>;<span>$j</span>--<span>){
                </span><span>if</span>(<span>$array</span>[<span>$j</span>]<<span>$array</span>[<span>$j</span>-1<span>]){
                    </span><span>$tmp</span> = <span>$array</span>[<span>$j</span><span>];
                    </span><span>$array</span>[<span>$j</span>] = <span>$array</span>[<span>$j</span>-1<span>];
                    </span><span>$array</span>[<span>$j</span>-1] = <span>$tmp</span><span>;
                    </span><span>$flag</span> = <span>true</span>;<span>//</span><span>发生了交换,故将交换标志置为真</span>
<span>                }
            }
        }
        </span><span>if</span>(!<span>$flag</span>)<span>//</span><span>本趟排序未发生交换,提前终止算法</span>
            <span>return</span> <span>$array</span><span>;
        
    }</span>
登入後複製

 待补充

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/1062611.htmlTechArticlephp的一些简单算法程序(冒泡、快速等),php算法程序冒泡 function buttle_sort( $array ) { $len = count ( $array ); if ( $len 2 ){ return $array ; } for ( $i =...
相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板