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);
Tags: analysis of algorithms, insertion sort, PHP, sort
No Comments
Comments RSS
TrackBack Identifier URI
No comments. Be the first.
Leave a comment