Created
April 20, 2015 12:53
-
-
Save you-think-you-are-special/9fdb82372bd10b5627e0 to your computer and use it in GitHub Desktop.
Bubble Sort
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function bubble_sort($array) | |
{ | |
$n = count($array); | |
for ($i = 0; $i < $n - 1; $i++) { | |
for ($j = 0; $j < $n - 1 - $i; $j++) { | |
if ($array[$j] > $array[$j + 1]) { | |
list($array[$j], $array[$j + 1]) = [$array[$j + 1], $array[$j]]; | |
} | |
} | |
} | |
return $array; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment