Home >Backend Development >PHP Tutorial >A simple method to implement quick sorting in php, sorting in php_PHP tutorial

A simple method to implement quick sorting in php, sorting in php_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 09:58:13716browse

A simple way to implement quick sorting in php, a simple way to implement sorting in php

The example in this article describes a simple way to implement quick sorting in php. Share it with everyone for your reference. The specific implementation method is as follows:

function quicksort($seq)
{
 if(!count($seq)) return $seq;
 $k = $seq[0];
 $x = $y = array();
 for($i=count($seq); --$i;)
 {
  if($seq[$i] <= $k)
  {
   $x[] = $seq[$i];
  }
  else
  {
   $y[] = $seq[$i];
  }
 }
 return array_merge(quicksort($x),array($k),quicksort($y));
}

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/979037.htmlTechArticleA simple method to implement quick sorting in php, php to implement sorting This article describes an example of a simple method to implement quick sorting in php. Share it with everyone for your reference. The specific implementation method is as follows: func...
Statement:
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