Konstantinos-infogeek
5/19/2016 - 11:52 PM

Insertion sort algorithm for php

Insertion sort algorithm for php

function shortNumbers(array $numbers){
	
	$counter = 1;
	for(;$counter < count($numbers); $counter++){
		$x = $numbers[$counter];
		$j = $counter - 1;
		while ( $j>=0 && $numbers[$j] > $x ){
			$numbers[$j + 1] = $numbers[$j];
			$j--;
		}
		$numbers[$j + 1] = $x;
	}

	return $numbers;
}