Fastest Insertion Sort in PHP

$numbers = array(2,3,4,5,1,8,11,0);
$count = count($numbers);

for($i=1;$i<$count;$i++){
	$j=$i-1;
	$key = $numbers[$i];
	while($j>=0 && $numbers[$j] >  $key){
		$numbers[$j+1] = $numbers[$j];
		$numbers[$j]= $key;
		$j= $j-1;
	}
}
print_r($numbers);
  • Share/Bookmark

Tags: , , ,

No Comments

rssComments RSS   transmitTrackBack Identifier URI

No comments. Be the first.

addLeave a comment