Skip to content

Commit

Permalink
minor readme change
Browse files Browse the repository at this point in the history
spirosmaggioros committed Feb 4, 2024
1 parent c2a66f5 commit aaa0c00
Showing 2 changed files with 21 additions and 18 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -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**
<a href="https://github.com/CSRT-NTUA/AlgoPlus/graphs/contributors">
<img src="https://contrib.rocks/image?repo=CSRT-NTUA/AlgoPlus" />
</a>
### 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
33 changes: 17 additions & 16 deletions src/algorithms/sorting/merge_sort.h
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
#ifndef ALGOPLUS_MERGE_SORT_H
#define ALGOPLUS_MERGE_SORT_H
#ifndef MERGE_SORT_H
#define MERGE_SORT_H

#include <algorithm> // Required for std::inplace_merge
#include <iostream>
#include <vector>
#include <algorithm> // 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 <typename Iter>
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 <typename Iter> 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

0 comments on commit aaa0c00

Please sign in to comment.