Aer Interpreter Source
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

27 lines
500 B

class Program {
public static int[] bubbleSort(int[] $arr) {
int $n = sizeof($arr);
for(int $i = 1; $i < $n; $i++) {
bool $flag = false;
for(int $j = $n - 1; $j >= $i; $j--) {
if($arr[$j-1] > $arr[$j]) {
int $tmp = $arr[$j - 1];
$arr[$j - 1] = $arr[$j];
$arr[$j] = $tmp;
$flag = true;
}
}
if(!$flag) {
break;
}
}
return $arr;
}
public void main() {
int[] $arr = {7, 9, 1, 2, 5, 6, 10, 14};
var_dump(Program::bubbleSort($arr));
}
}