<?php
function arrayGen() {
$array = [];
for ($i=0; $i<=200; $i++) {
}
return $array;
}
function arrayShow($array) {
echo implode($array, ", ") . ".\n"; }
function bubbleSorting($array) {
for ($i=0; $i<count($array)-1; $i++) { for ($j=0; $j < count($array)-1; $j++) { if ($array[$j] > $array[$j+1]) {
$a = $array[$j];
$array[$j] = $array[$j+1];
$array[$j+1] = $a;
}
}
}
echo "Сортировка пузырьком выполненна за $time.\n";
return $array;
}
function newBubbleSorting($array) {
$sorted = FALSE;
while ($sorted == FALSE) {
$flag = 0;
for ($i=0; $i < count($array)-1; $i++) { if ($array[$i] > $array[$i+1]) {
$a = $array[$i];
$array[$i] = $array[$i+1];
$array[$i+1] = $a;
$flag++;
}
}
if ($flag == 0) {
$sorted = TRUE;
}
}
echo "Сортировка пузырьком 2.0 выполненна за $time.\n";
return $array;
}
$a = arrayGen();
//echo "Сгенерированный массив: ";
//arrayShow($a);
$b = bubbleSorting($a);
//echo "Сортировка пузырьком: ";
//arrayShow($b);
$c = newBubbleSorting($a);
//echo "пузырек 2.0: ";
//arrayShow ($c);
PD9waHAKZXJyb3JfcmVwb3J0aW5nKC0xKTsKCmZ1bmN0aW9uIGFycmF5R2VuKCkgewoJJGFycmF5ID0gW107Cglmb3IgKCRpPTA7ICRpPD0yMDA7ICRpKyspIHsKCQkkYXJyYXlbJGldID0gbXRfcmFuZCgxMCw5OSk7Cgl9CglyZXR1cm4gJGFycmF5Owp9CgpmdW5jdGlvbiBhcnJheVNob3coJGFycmF5KSB7CgllY2hvIGltcGxvZGUoJGFycmF5LCAiLCAiKSAuICIuXG4iOwp9CgoKZnVuY3Rpb24gYnViYmxlU29ydGluZygkYXJyYXkpIHsKCSRzdGFydFRpbWUgPSBtaWNyb3RpbWUoKTsKCWZvciAoJGk9MDsgJGk8Y291bnQoJGFycmF5KS0xOyAkaSsrKSB7CgkJZm9yICgkaj0wOyAkaiA8IGNvdW50KCRhcnJheSktMTsgJGorKykgewoJCQlpZiAoJGFycmF5WyRqXSA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