-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsort_exercise.php
More file actions
86 lines (73 loc) · 976 Bytes
/
sort_exercise.php
File metadata and controls
86 lines (73 loc) · 976 Bytes
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
$a = array(
1013,
955,
1042,
1137,
1316,
899,
1154,
1100,
954,
946,
1285,
1270,
1216,
986,
898,
924,
1066,
987,
1031,
1141,
1377,
1108,
1180,
1322,
1135,
936,
996,
1087,
978,
1314,
1170,
1307,
1014,
975,
1189,
922,
1223,
1327,
1226,
1016,
1272,
871,
1199,
888,
1040,
959,
1066,
1066,
1060,
923,
1035,
939,
);
// divide the array in two halves. If the array has 20 elements,
// the first array has to contain the first 10 elements, and the second
// array has to contain the last 10 elements. Do not change the order of
// the elements.
// If the array has an odd number of elements, make the first half one
// element larger than the second.
// If the array has less than two elements, put all elements in the first
// half and leave the second half empty.
// The solution has to be a function.
// This template can be used:
function halve(array $a) {
$h1 = array();
$h2 = array();
....
print_r($h1);
print_r($h2);
}
halve($a);