Bubble Sort function bubbleSort(array $arr) { $n = sizeof($arr); for ($i = 1; $i < $n; $i++) { for ($j = $n - 1; $j >= $i; $j--) { if($arr[$j-1] > $arr[$j]) { $tmp = $arr[$j - 1]; $arr[$j - 1] = $arr[$j]; $arr[$j] = $tmp; } } } return $arr; } $arr = array(255,1,22,3,45,5); $result = bubbleSort($arr); print_r($result); ---------------------------------------------x---------------------------------------------- Selection Sort function selectionSort(array $arr) { $n = sizeof($arr); for ($i = 0; $i < $n; $i++) { $lowestValueIndex = $i; $lowestValue = $arr[$i]; for ($j = $i + 1; $j < $n; $j++) { if ($arr[$j] < $lowestValue) { $lowestValueIndex = $j; ...
Coding Cheatsheets - Learn web development code and tutorials for Software developers which will helps you in project. Get help on JavaScript, PHP, XML, and more.