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
| #pragma once
|
| namespace mapbox {
| namespace geometry {
| namespace wagyu {
|
| template <typename It, class Compare, class MethodOnSwap>
| void bubble_sort(It begin, It end, Compare c, MethodOnSwap m) {
| if (begin == end) {
| return;
| }
| bool modified = false;
| auto last = end - 1;
| do {
| modified = false;
| for (auto itr = begin; itr != last; ++itr) {
| auto next = std::next(itr);
| if (!c(*itr, *next)) {
| m(*itr, *next);
| std::iter_swap(itr, next);
| modified = true;
| }
| }
| } while (modified);
| }
| } // namespace wagyu
| } // namespace geometry
| } // namespace mapbox
|
|