32 #ifndef ACE_SORTING_SELECTION_SORT_H
33 #define ACE_SORTING_SELECTION_SORT_H
37 namespace ace_sorting {
39 #if ! defined(ACE_SORTING_DIRECT_SELECTION_SORT)
46 #define ACE_SORTING_DIRECT_SELECTION_SORT 0
56 #if ACE_SORTING_DIRECT_SELECTION_SORT
58 void selectionSort(T data[], uint16_t n) {
59 for (uint16_t i = 0; i < n; i++) {
62 uint16_t iSmallest = i;
69 for (uint16_t j = i; j < n; j++) {
70 if (data[j] < smallest) {
83 swap(data[i], data[iSmallest]);
92 auto&& lessThan = [](
const T& a,
const T& b) ->
bool {
return a < b; };
104 template <
typename T,
typename F>
106 for (uint16_t i = 0; i < n; i++) {
109 uint16_t iSmallest = i;
110 T smallest = data[i];
116 for (uint16_t j = i; j < n; j++) {
117 if (lessThan(data[j], smallest)) {
129 if (i != iSmallest) {
130 swap(data[i], data[iSmallest]);