codex
Loading...
Searching...
No Matches
insertion.hpp
Go to the documentation of this file.
1#ifndef CODEX_SORT_INSERTION_H
2#define CODEX_SORT_INSERTION_H
3
4#include <algorithm>
5#include <cassert>
6
7namespace codex {
8
9template<std::permutable I, std::sentinel_for<I> S>
10requires std::bidirectional_iterator<I>
11void insertion_sort(I b, S e) {
12 for(auto i = b; i != e; ++i) {
13 assert(std::is_sorted(b, i));
14 for(auto p = i, np = std::prev(i); p != b && *p < *np; p = np--) {
15 assert(std::is_sorted(b, p));
16 assert(std::is_sorted(p, i));
17 std::iter_swap(np, p);
18 }
19 }
20 assert(std::is_sorted(b, e));
21}
22
23}
24
25#endif
Definition rotate.hpp:6
void insertion_sort(I b, S e)
Definition insertion.hpp:11
#define p()
Definition std2.c:11
Definition reflexpr.cpp:168
Definition mult_inh.c:26