選擇排序
//
// Created by krislyy on 2018/11/14.
//
#ifndef ALGORITHM_SELECTSORT_H
#define ALGORITHM_SELECTSORT_H
#include "utility.h"
namespace Algorithm {
template <typename T>
static int max(T *Array, int lo, int hi) {
int mx = hi;
while (lo < hi--) {
if (Array[hi] > Array[mx]) {
mx = hi;
}
}
return mx;
}
template <typename T>
static void SelectSort(T *Array, int lo, int hi) {
while (lo < --hi) {
swap(Array[max(Array, lo, hi)], Array[hi]);
}
}
}
#endif //ALGORITHM_SELECTSORT_H