tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
exchange_sort.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2
3#ifndef TETL_ALGORITHM_EXCHANGE_SORT_HPP
4#define TETL_ALGORITHM_EXCHANGE_SORT_HPP
5
10
11namespace etl {
12
17template <typename RandomIt, typename Compare>
18constexpr auto exchange_sort(RandomIt first, RandomIt last, Compare comp) -> void
19{
20 for (auto i = first; i < etl::prev(last); ++i) {
21 for (auto j = etl::next(i); j < last; ++j) {
22 if (comp(*j, *i)) {
23 etl::iter_swap(i, j);
24 }
25 }
26 }
27}
28
33template <typename RandomIt>
34constexpr auto exchange_sort(RandomIt first, RandomIt last) -> void
35{
36 etl::exchange_sort(first, last, etl::less());
37}
38
39} // namespace etl
40
41#endif // TETL_ALGORITHM_EXCHANGE_SORT_HPP
constexpr auto exchange_sort(RandomIt first, RandomIt last, Compare comp) -> void
Sorts the elements in the range [first, last) in non-descending order.
Definition exchange_sort.hpp:18
constexpr auto iter_swap(ForwardIt1 a, ForwardIt2 b) -> void
Swaps the values of the elements the given iterators are pointing to.
Definition iter_swap.hpp:19
constexpr auto prev(BidirIt it, typename iterator_traits< BidirIt >::difference_type n=1) -> BidirIt
Return the nth predecessor of iterator it.
Definition prev.hpp:14
constexpr auto next(InputIt it, typename iterator_traits< InputIt >::difference_type n=1) -> InputIt
Return the nth successor of iterator it.
Definition next.hpp:14
Definition adjacent_find.hpp:8
Function object for performing comparisons. Unless specialised, invokes operator< on type T....
Definition less.hpp:14