mirror of
https://github.com/aicodix/code.git
synced 2026-04-27 14:30:36 +00:00
start with insertion sort for better speed
This commit is contained in:
parent
2d5e782135
commit
ac5fc8deea
1 changed files with 4 additions and 2 deletions
6
sort.hh
6
sort.hh
|
|
@ -34,7 +34,7 @@ static void insertion_sort(INDEX *p, TYPE *a, int n)
|
|||
}
|
||||
}
|
||||
|
||||
template <typename TYPE, int MAX_N>
|
||||
template <typename TYPE, int MAX_N, int M = 32>
|
||||
class MergeSort
|
||||
{
|
||||
TYPE tmp[MAX_N];
|
||||
|
|
@ -50,7 +50,9 @@ class MergeSort
|
|||
public:
|
||||
void operator()(TYPE *a, int n)
|
||||
{
|
||||
for (int l = 1; l < n; l *= 2) {
|
||||
for (int i = 0; i < n; i += M)
|
||||
insertion_sort(a+i, i > n-M ? n-i : M);
|
||||
for (int l = M; l < n; l *= 2) {
|
||||
for (int i = 0; i < n; i += 2*l)
|
||||
merge(a, n, i, i+l, i+2*l);
|
||||
for (int i = 0; i < n; ++i)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue