Home > php教程 > php手册 > PHP排序算法:快速排序算法

PHP排序算法:快速排序算法

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-06 19:35:22
Original
1193 people have browsed it

PHP排序算法:快速排序算法 无 /* * 快速排序算法 */function quickSort($array){$len = count($array);if($len = 1){return $array;}$left_array = array();$right_array = array();$key = $array[0];for($i=1;$i$len;$i++){if($array[$i]$key){$left_array[

PHP排序算法:快速排序算法
/*
 * 快速排序算法
 */

function quickSort($array){
	$len = count($array);
	if($len <= 1){
		return $array;
	}
	
	$left_array = array();
	$right_array = array();
	
	$key = $array[0];
	for($i=1;$i<$len;$i++){
		if($array[$i]<$key){
			$left_array[] = $array[$i];
		}else{
			$right_array[] = $array[$i];
		}
	}
	
	$left_array = quickSort($left_array);
	$right_array = quickSort($right_array);
	
	return array_merge($left_array,array($key),$right_array);
	
}

$sortarray = array(13,89,23,9,19,88,56,78,34,69,10,14);
print_r(quickSort($sortarray));
Copy after login
Related labels:
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template