Bozo Sort is more efficient than than bogosort(in theory). It does sorting by randomly chose 2 items and compare them, then switch them if needed. Until everything is sorted.
function bozo_sort($array){ $sorted = $array; sort($sorted); while($sorted !== $array){ $i = array_rand($array); $j = array_rand($array); if($i < $j){ if($array[$i] > $array[$j]){ $z = $array[$j]; $array[$j] = $array[$i]; $array[$i] = $z; } }else{ if($array[$j] > $array[$i]){ $z = $array[$i]; $array[$i] = $array[$j]; $array[$j] = $z; } } } return $array; }
Comments
Post new comment