diff --git a/README.md b/README.md index d8e8705a..3c02f549 100644 --- a/README.md +++ b/README.md @@ -64,6 +64,10 @@ You can see more [examples](/examples) or follow the [Tutorials](/tutorial). - [X] [Stack](https://en.wikipedia.org/wiki/Stack_(abstract_data_type)) - [X] [Queue](https://en.wikipedia.org/wiki/Queue_(abstract_data_type)) +### **Our contributors** + + + ### How to contribute 1. Povide **new implementations** on our already implemented data structures & algorithms. @@ -80,5 +84,3 @@ You can see more [examples](/examples) or follow the [Tutorials](/tutorial). 4. **Promote** the repository on your local workshop/seminar and **get a shout-out**. See more [here](/CONTRIBUTE.md). - -The authors diff --git a/src/algorithms/sorting/merge_sort.h b/src/algorithms/sorting/merge_sort.h index b9ee9849..7cad04c2 100644 --- a/src/algorithms/sorting/merge_sort.h +++ b/src/algorithms/sorting/merge_sort.h @@ -1,27 +1,28 @@ -#ifndef ALGOPLUS_MERGE_SORT_H -#define ALGOPLUS_MERGE_SORT_H +#ifndef MERGE_SORT_H +#define MERGE_SORT_H +#include // Required for std::inplace_merge #include #include -#include // Required for std::inplace_merge /** * @brief Performs a merge sort on a range of elements. * @param begin An iterator to the beginning of the range to be sorted. * @param end An iterator to the end of the range to be sorted. - * @details This function sorts the elements in the range [begin, end) into ascending order. - * The sort is performed in-place. It divides the range into two halves, recursively sorts each half, - * and then merges the two sorted halves together. The function requires that the range of elements - * is sortable by the criteria used in std::inplace_merge. + * @details This function sorts the elements in the range [begin, end) into + * ascending order. The sort is performed in-place. It divides the range into + * two halves, recursively sorts each half, and then merges the two sorted + * halves together. The function requires that the range of elements is sortable + * by the criteria used in std::inplace_merge. */ -template -void merge_sort(Iter begin, Iter end) { - if (end - begin > 1) { - Iter mid = begin + (end - begin) / 2; // Assumes Random Access Iterator - merge_sort(begin, mid); - merge_sort(mid, end); - std::inplace_merge(begin, mid, end); // Elements must be comparable and move-assignable - } +template void merge_sort(Iter begin, Iter end) { + if (end - begin > 1) { + Iter mid = begin + (end - begin) / 2; // Assumes Random Access Iterator + merge_sort(begin, mid); + merge_sort(mid, end); + std::inplace_merge(begin, mid, + end); // Elements must be comparable and move-assignable + } } -#endif //ALGOPLUS_MERGE_SORT_H +#endif // MERGE_SORT_H