-
Notifications
You must be signed in to change notification settings - Fork 1
/
razeni.php
51 lines (42 loc) · 974 Bytes
/
razeni.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<style>
td{
padding: 10px;
}
</style>
<?
function vypis_pole($p){
?><table><tr><td><?
echo implode("</td><td>",$p);
?></td></tr></table><?
}
function bubblesort($p){
for($i=0;$i<count($p)-1;$i++):
for($j=0;$j<count($p)-$i-1;$j++):
if($p[$j]>$p[$j+1]):
$q = $p[$j];
$p[$j] = $p[$j+1];
$p[$j+1] = $q;
endif;
endfor;
endfor;
return $p;
}
function selectionsort($p){
for($i=0;$i<count($p)-1;$i++):
$nejmensi = $p[$i];
$nejmensi_i = $i;
for($j=$i+1;$j<count($p);$j++):
if($p[$j]<$nejmensi):
$nejmensi = $p[$j];
$nejmensi_i = $j;
endif;
endfor;
$p[$nejmensi_i] = $p[$i];
$p[$i] = $nejmensi;
endfor;
return $p;
}
$x = array(5,4,18,1,-2,6,12,4,6,7,2,10,13,9,-6,0,4,-9);
vypis_pole($x);
vypis_pole(selectionsort($x));
?>