15template<typename T, typename = typename std::enable_if<std::is_arithmetic<T>::value, T>::type>
16void insertion_sort(
const T& elem, std::vector<T>& vec,
const int& current_index) {
17 int i = current_index;
19 if(vec[i - 1] < elem) {
break; }
32template<typename T, typename = typename std::enable_if<std::is_arithmetic<T>::value, T>::type>
33std::vector<T>
sort(
const std::vector<T>& in) {
34 std::vector<T> out(in.size());
46 int i = current_index;
47 if(current_index > 0) {
49 if(out(i - 1, 0) < elem) {
break; }
50 out(i, 0) = out(i - 1, 0);
58 bool requires_transposition = in.
rows() < in.
columns();
59 auto _in = requires_transposition ? in.
Transpose() : in;
61 for(
int i = 0; i < _in.rows(); ++i) {
insertion_sort(_in(i, 0), out, i); }
62 return requires_transposition ? out.
Transpose() : out;
constexpr Matrix< T > Transpose() const
Definition: Matrix.h:256
size_t rows() const
Definition: Matrix.h:193
size_t columns() const
Definition: Matrix.h:198
void insertion_sort(const T &elem, std::vector< T > &vec, const int ¤t_index)
Definition: sorting.h:16
std::vector< T > sort(const std::vector< T > &in)
Definition: sorting.h:33