File tree Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ function checkForNextLine ($ arr )
4
+ {
5
+ $ length = sizeof ($ arr );
6
+
7
+ for ($ i = 0 ; $ i < $ length ; $ i ++) {
8
+ if (strpos ($ arr [$ i ], "\n" ) === false ) {
9
+ $ arr [$ i ] .= "\n" ;
10
+ }
11
+ }
12
+
13
+ return $ arr ;
14
+ }
15
+
16
+ function bubbleSort ($ sort_array )
17
+ {
18
+ $ array_indexes = count ($ sort_array );
19
+ $ sorted = false ;
20
+
21
+ for ($ i = 0 ; $ i < $ array_indexes ; $ i ++) {
22
+ for ($ j = 0 ; $ j < $ array_indexes - $ i - 1 ; $ j ++) {
23
+ if ($ sort_array [$ j + 1 ] < $ sort_array [$ j ]) {
24
+ $ tmp = $ sort_array [$ j + 1 ];
25
+ $ sort_array [$ j + 1 ] = $ sort_array [$ j ];
26
+ $ sort_array [$ j ] = $ tmp ;
27
+
28
+ $ sorted = true ;
29
+ }
30
+ }
31
+
32
+ if (! $ sorted ) {
33
+ break ;
34
+ }
35
+ }
36
+
37
+ return $ sort_array ;
38
+ }
39
+
40
+ echo implode ("" , bubbleSort (checkForNextLine (file ('php://stdin ' ))));
You can’t perform that action at this time.
0 commit comments