Fix logic bug in quick sort routine. This would result in infinite recursion such as that in bug #2343.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25831 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Rene Gollent
2008-06-06 21:01:51 +00:00
parent a92156e1cf
commit e90b17a854
+7 -5
View File
@@ -27,6 +27,9 @@ static void
quick_sort_item_array(BListItem** items, int32 first, int32 last, quick_sort_item_array(BListItem** items, int32 first, int32 last,
int (*compareFunc)(const BListItem* a, const BListItem* b)) int (*compareFunc)(const BListItem* a, const BListItem* b))
{ {
printf("quick_sort_item_array(items: %p, first: %ld, last: %ld, comparefunc: %p)\n",
items, first, last, compareFunc);
if (last <= first) if (last <= first)
return; return;
@@ -42,7 +45,6 @@ quick_sort_item_array(BListItem** items, int32 first, int32 last,
while ((compareFunc(items[right], pivot) > 0) && (right > first)) while ((compareFunc(items[right], pivot) > 0) && (right > first))
right--; right--;
if (left < right) { if (left < right) {
// swap entries // swap entries
@@ -61,13 +63,13 @@ quick_sort_item_array(BListItem** items, int32 first, int32 last,
// At this point, the elements in the left half are all smaller // At this point, the elements in the left half are all smaller
// than the elements in the right half // than the elements in the right half
if (first < right) { if (first < left) {
// sort left half // sort left half
quick_sort_item_array(items, first, right, compareFunc); quick_sort_item_array(items, first, left, compareFunc);
} }
if (left < last) { if (right < last) {
// sort right half // sort right half
quick_sort_item_array(items, left, last, compareFunc); quick_sort_item_array(items, right, last, compareFunc);
} }
} }