Commit 1d241bb2 authored by Stefan Oberhumer's avatar Stefan Oberhumer Committed by Alexandre Julliard

ntdll: Make NTDLL_mergesort() stable.

parent 98134a8c
...@@ -270,9 +270,9 @@ NTDLL_mergesort( void *arr, void *barr, size_t elemsize, int(__cdecl *compar)(co ...@@ -270,9 +270,9 @@ NTDLL_mergesort( void *arr, void *barr, size_t elemsize, int(__cdecl *compar)(co
for (j=m; j<right; j++) for (j=m; j<right; j++)
memcpy (X(barr,(right+m-j)),X(arr,(j+1)),elemsize); memcpy (X(barr,(right+m-j)),X(arr,(j+1)),elemsize);
for (k=left; k<=right; k++) { /* i=left; j=right; */
/*arr[k]=(barr[i]<barr[j])?barr[i++]:barr[j--];*/ for (k=left; i<=m && j>m; k++) {
if (i != j && compar(X(barr,i),X(barr,j))<0) { if (compar(X(barr,i),X(barr,j))<=0) {
memcpy(X(arr,k),X(barr,i),elemsize); memcpy(X(arr,k),X(barr,i),elemsize);
i++; i++;
} else { } else {
...@@ -280,6 +280,10 @@ NTDLL_mergesort( void *arr, void *barr, size_t elemsize, int(__cdecl *compar)(co ...@@ -280,6 +280,10 @@ NTDLL_mergesort( void *arr, void *barr, size_t elemsize, int(__cdecl *compar)(co
j--; j--;
} }
} }
for (; i<=m; i++, k++)
memcpy(X(arr,k),X(barr,i),elemsize);
for (; j>m; j--, k++)
memcpy(X(arr,k),X(barr,j),elemsize);
} }
#undef X #undef X
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment