tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
merge_sort.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2
3#ifndef TETL_ALGORITHM_MERGE_SORT_HPP
4#define TETL_ALGORITHM_MERGE_SORT_HPP
5
8
9namespace etl {
10
13
17template <typename BidirIt, typename Compare>
18constexpr auto merge_sort(BidirIt first, BidirIt last, Compare comp) -> void
19{
20 if (last - first > 1) {
21 BidirIt mid = first + (last - first) / 2;
22 etl::merge_sort(first, mid, comp);
23 etl::merge_sort(mid, last, comp);
24 etl::inplace_merge(first, mid, last, comp);
25 }
26}
27
28template <typename BidirIt>
29constexpr auto merge_sort(BidirIt first, BidirIt last) -> void
30{
31 etl::merge_sort(first, last, etl::less());
32}
33
35
36} // namespace etl
37
38#endif // TETL_ALGORITHM_MERGE_SORT_HPP
constexpr auto merge_sort(BidirIt first, BidirIt last, Compare comp) -> void
Sorts the elements in the range [first, last) in non-descending order.
Definition merge_sort.hpp:18
constexpr auto inplace_merge(BidirIt begin, BidirIt mid, BidirIt end, Compare comp) -> void
Merges two consecutive sorted ranges [first, middle) and [middle, last) into one sorted range [first,...
Definition inplace_merge.hpp:25
Definition adjacent_find.hpp:8
Function object for performing comparisons. Unless specialised, invokes operator< on type T....
Definition less.hpp:14