PHP implementation of Pancake sort

PHP implementation of Pancake sort, the very mathy but slow(at least in PHP) sort.

function pancake_sort($array){
	$count = count($array);
	$powercount = $count - 1;
	$i = 0;
	while($i < $powercount){
		$n = 0;
		$largest = 0;
		while($n < $count){
			if($array[$largest]<$array[$n]){
				$largest = $n;
			}
			++$n;
		}
		$num = $largest/2;
		$j = 0;
		while($j < $num){
			$z = $array[$largest-$j];
			$array[$largest-$j] = $array[$j];
			$array[$j] = $z;
			++$j;
 
		}
		$num = --$count/2;
		$j = 0;
		while($j<$num){
			$z = $array[$count-$j];
			$array[$count-$j] = $array[$j];
			$array[$j] = $z;
			++$j;
		}
		++$i;
	}
	return $array;
}

Post new comment

The content of this field is kept private and will not be shown publicly.
If you have a Gravatar account, used to display your avatar.
  • Allowed HTML tags: <img> <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <span> <fn>
  • Lines and paragraphs break automatically.
  • Textual smileys will be replaced with graphical ones.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>. Beside the tag style "<foo>" it is also possible to use "[foo]".
  • Use [fn]...[/fn] (or <fn>...</fn>) to insert automatically numbered footnotes.

More information about formatting options

What is 3 + 93?
To combat spam, please solve the math question above.
Honey Pot that kill bots