tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
bubble_sort.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2
3#ifndef TETL_ALGORITHM_BUBBLE_SORT_HPP
4#define TETL_ALGORITHM_BUBBLE_SORT_HPP
5
8
9namespace etl {
10
13
20template <typename RandomIt, typename Compare>
21constexpr auto bubble_sort(RandomIt first, RandomIt last, Compare comp) -> void
22{
23 for (auto i = first; i != last; ++i) {
24 for (auto j = first; j < i; ++j) {
25 if (comp(*i, *j)) {
26 etl::iter_swap(i, j);
27 }
28 }
29 }
30}
31
38template <typename RandomIt>
39constexpr auto bubble_sort(RandomIt first, RandomIt last) -> void
40{
41 etl::bubble_sort(first, last, etl::less());
42}
43
45
46} // namespace etl
47
48#endif // TETL_ALGORITHM_BUBBLE_SORT_HPP
constexpr auto bubble_sort(RandomIt first, RandomIt last, Compare comp) -> void
Sorts the elements in the range [first, last) in non-descending order. The order of equal elements is...
Definition bubble_sort.hpp:21
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
Definition adjacent_find.hpp:8
Function object for performing comparisons. Unless specialised, invokes operator< on type T....
Definition less.hpp:14