<?php
function quickSort($startID,$endID) {
	global $a;
	$pivot = $a[(int)(($startID + $endID)/2)];
	$left = $startID;
	$right = $endID;
	while (true) {
		while ($a[$left] < $pivot) {
			$left++;
		}
		while ($pivot < $a[$right]) {
			$right--;
		}
		if ($right <=$left) {
			break;
		}
		$tmp = $a[$left];
		$a[$left] = $a[$right];
		$a[$right] = $tmp;
		$left++;
	}
	if ($startID < $left-1) {
		quickSort($right+1,$endID);
	}
}
$a = array(10,3,1,9,7,6,8,2,4,5);
quickSort(0, count($a)-1);
print_r($a);
?>
