A simple quick sort

Source: Internet
Author: User

<?php/** * created by phpstorm. * user: saint * date: 15/ 8/5 * time:  Morning 11:49 */class demo{    public  $a  =  Array (3, 6, 9, 2, 4, 7, 1, 5, 8, 0);     Public function qsort ($left,  $right)     {         if ($left  >  $right)  {             return;        }          $i  =  $left;         $j  =  $right;          $standard  =  $this->a[$left];         while ($i  !=  $j)  {             //  Find cells             while from right to left that are smaller than the base number ($standard   <=  $this->a[$j])  &&  ($j  >  $i))  {                  $j--;             }            / /  from left to right to find             while (($standard  >=  $this->a[$i])  &&  ($j  >  $i))  {                  $i ++;             }              $tmp  =  $this->a[$i];              $this->a[$i] =  $this->a[$j];             $this->a[$j]  =  $tmp;        }         //  determine the position of the base number          $this->a[$left] =  $this- >a[$i];         $this->a[$i] =  $standard;          $this->qsort ($left,  $i  - 1);          $this->qsort ($i  + 1,  $right);    }     //  execution Function     public function main ()     {          $left  = 0;          $right  = count ($this->a)  - 1;        $ This->qsort ($left,  $right);         print_r ($this->a);     }} $demo  = new demo (); $demo->main ();


A simple quick sort

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.