-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstd.cpp
49 lines (39 loc) · 1.26 KB
/
std.cpp
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
// a wrapper to use sort methods from the C++ standard library: qsort, sort_heap, sort, stable_sort
template <class T>
void qsort0(vector<T> &a) {
qsort((void*)&a[0], SS, sizeof(T), cmpfunc<T>);
}
template <>
void qsort0(vector<const char*> &a) {
qsort((void*)&a[0], SS, sizeof(char*), cmpfunc<const char*>);
}
template <>
void qsort0(vector<int64_t> &a) {
qsort((void*)&a[0], SS, sizeof(char*), cmpfunc<int64_t>);
}
template <class T>
void hsortstl(vector<T> &a) {
make_heap(a.begin(), a.end());
sort_heap(a.begin(), a.end());
}
template <>
void hsortstl(vector<const char*> &a) {
make_heap(a.begin(), a.end(), [](const char *l, const char *r) { return strcmp(l, r) < 0; });
sort_heap(a.begin(), a.end(), [](const char *l, const char *r) { return strcmp(l, r) < 0; });
}
template <class T>
void stl_sort(vector<T> &a) {
sort(a.begin(), a.end());
}
template <>
void stl_sort(vector<const char*> &a) {
sort(a.begin(), a.end(), [](const char *l, const char *r) { return strcmp(l, r) < 0; });
}
template <class T>
void stl_stable_sort(vector<T> &a) {
stable_sort(a.begin(), a.end());
}
template <>
void stl_stable_sort(vector<const char*> &a) {
stable_sort(a.begin(), a.end(), [](const char *l, const char *r) { return strcmp(l, r) < 0; });
}