Commit f97b5434 authored by Mike McCormack's avatar Mike McCormack Committed by Alexandre Julliard

Rewrote quicksort to solve infinite recursions Win98 explorer.exe.

parent 627616b8
...@@ -1614,26 +1614,35 @@ static VOID ...@@ -1614,26 +1614,35 @@ static VOID
DPA_QuickSort (LPVOID *lpPtrs, INT l, INT r, DPA_QuickSort (LPVOID *lpPtrs, INT l, INT r,
PFNDPACOMPARE pfnCompare, LPARAM lParam) PFNDPACOMPARE pfnCompare, LPARAM lParam)
{ {
LPVOID t, v; INT m;
INT i, j; LPVOID t;
TRACE("l=%i r=%i\n", l, r); TRACE("l=%i r=%i\n", l, r);
i = l; if (l==r) /* one element is always sorted */
j = r; return;
v = lpPtrs[(int)(l+r)/2]; if (r<l) /* oops, got it in the wrong order */
do {
while ((pfnCompare)(lpPtrs[i], v, lParam) < 0) i++;
while ((pfnCompare)(lpPtrs[j], v, lParam) > 0) j--;
if (i <= j)
{ {
t = lpPtrs[i]; DPA_QuickSort(lpPtrs, r, l, pfnCompare, lParam);
lpPtrs[i++] = lpPtrs[j]; return;
lpPtrs[j--] = t;
} }
} while (i <= j); m = (l+r)/2; /* divide by two */
if (l < j) DPA_QuickSort (lpPtrs, l, j, pfnCompare, lParam); DPA_QuickSort(lpPtrs, l, m, pfnCompare, lParam);
if (i < r) DPA_QuickSort (lpPtrs, i, r, pfnCompare, lParam); DPA_QuickSort(lpPtrs, m+1, r, pfnCompare, lParam);
/* join the two sides */
while( (l<=m) && (m<r) )
{
if(pfnCompare(lpPtrs[l],lpPtrs[m+1],lParam)>0)
{
t = lpPtrs[m+1];
memmove(&lpPtrs[l+1],&lpPtrs[l],m-l+1);
lpPtrs[l] = t;
m++;
}
l++;
}
} }
......
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