Help with QuickSort

My quicksort function isn't sorting all of my entries. It will sort most of it but it'll miss a couple others.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
void qsort(Dict DictEntries[MAXENTRIES],int start,int finish)
{
  int left=start,
      right=finish;
  char *pivot=DictEntries[(start+finish)/2].key;
  while (left < right) {
    // find left candidate
    while ((strcmp(DictEntries[left].key,pivot)<0) && (left<right)) left++; 
    // find right candidate	
    while ((strcmp(DictEntries[right].key,pivot)>0) && (right>left)) right--; 
    if (left <= right) {
      Dict temp = DictEntries[left];
      DictEntries[left] = DictEntries[right];
      DictEntries[right] = temp;
	  left++;
  	  right--;
    } 
  } // while left < right
  if (start < right) qsort(DictEntries,start,right);
  if (left < finish) qsort(DictEntries,left,finish);
}
closed account (o3hC5Di1)
Hi there,

Duoas recently wrote a great article about quicksort, explaining many of the implementation options and optimizations:
http://www.cplusplus.com/faq/sequences/sequencing/sort-algorithms/quicksort/

Perhaps that can be of help.

All the best,
NwN
Topic archived. No new replies allowed.