-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.hpp
More file actions
44 lines (36 loc) · 833 Bytes
/
util.hpp
File metadata and controls
44 lines (36 loc) · 833 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
template <typename T, size_t N>
class Vec {
T values[N] = {};
size_t length = 0;
public:
size_t len() const {
return length;
}
T& operator[](size_t index) {
return values[index];
}
T& last() {
return values[length - 1];
}
void push(T value) {
values[length] = value;
length++;
}
template <typename C>
void sort(C swap) {
bool swapped = true;
while (swapped) {
swapped = false;
for (size_t i = 1; i < length; i++) {
T& a = values[i - 1];
T& b = values[i];
if (swap(a, b)) {
T temp = a;
a = b;
b = temp;
swapped = true;
}
}
}
}
};