Home  >  Article  >  Backend Development  >  Detailed explanation of method examples for implementing quick sorting in PHP

Detailed explanation of method examples for implementing quick sorting in PHP

怪我咯
怪我咯Original
2017-07-04 14:55:361193browse

This article mainly introduces how to simply implement quick sorting in PHP, involving PHP's operating skills for array and string. It has certain reference value. Friends who need it can Refer to the following

The example of this article describes how to simply 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));
}

The above is the detailed content of Detailed explanation of method examples for implementing quick sorting in PHP. For more information, please follow other related articles on the PHP Chinese website!

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