diff --git a/BAN/include/BAN/Sort.h b/BAN/include/BAN/Sort.h index 22af766dda..46b2f9f876 100644 --- a/BAN/include/BAN/Sort.h +++ b/BAN/include/BAN/Sort.h @@ -43,15 +43,26 @@ namespace BAN template> void sort_quick(It begin, It end, Comp comp = {}) { - { - It it = begin; - if (it == end || ++it == end) - return; - } - + if (begin == end || next(begin, 1) == end) + return; It mid = detail::sort_quick_partition(begin, end, comp); sort_quick(begin, mid, comp); sort_quick(++mid, end, comp); } + template> + void sort_insertion(It begin, It end, Comp comp = {}) + { + if (begin == end) + return; + for (It it1 = next(begin, 1); it1 != end; ++it1) + { + typename It::value_type x = move(*it1); + It it2 = it1; + for (; it2 != begin && comp(x, *prev(it2, 1)); --it2) + *it2 = move(*prev(it2, 1)); + *it2 = move(x); + } + } + }