A simple method to implement quick sorting in php_PHP tutorial

WBOY
Release: 2016-07-13 09:58:00
Original
937 people have browsed it

A simple way to implement quick sorting in PHP

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

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

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));

}

1 2 3

4

6 7 8 9 10
11 12
13 14 15 16 17 18
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)); }
http://www.bkjia.com/PHPjc/979236.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/979236.htmlTechArticleA simple method to implement quick sorting in PHP. This article describes a simple method to implement quick sorting in PHP. Share it with everyone for your reference. The specific implementation method is as follows: 1 2 3 4 5 6 7 8 9 10 1...
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!