0

Does anyone know the code to show the critical count for a quick sort algorithm.

Basically my cd database is almost finished.

What i need to do is show a critical count for the quicksort

quicksort for my database

```
void q_sort (struct CdRecords array [], int count)
{
quick_sort(array,0,count-1);
}
void quick_sort (struct CdRecords array [], int left, int right)
{
int i, j;
char *x;
struct CdRecords temp;
i = left;
j = right;
x = array[(left+right)/2].Genre;
do {
while(strcmp(array[i].Genre,x)<0 && i<right) i++;
while(strcmp(array[i].Genre,x)>0 && j>left) j--;
if(i<=j) {
temp = array[i];
array[i] = array[j];
array[j] = temp;
i++; j--;
}
}while(i<=j);
if(left<j) quick_sort(array, left, j);
if(i<right)quick_sort(array, i, right);
}
```

i used a naive sort and was able to show a critical count for that as shown below:

```
void naive_sort (struct CdRecords array [], int arraySize, int * count)
{
for (int pass = 0; pass <= arraySize - 2; pass++)
{ for (int counter = 0; counter <= arraySize - 2-pass; counter++)
{
*count = *count + 1; // count critical operations
if (strcmp(array[counter].Artist,array[counter+1].Artist)>0)
swap (&array[counter], &array[counter+1]);
}
}
}
// Exchange a given pair of values in an array
void swap (struct CdRecords * v1, struct CdRecords * v2)
{
struct CdRecords temp;
temp = *v1;
*v1 = *v2;
*v2 = temp;
}
```

critical count for naive sort

```
void sort_critical_count(struct CdRecords cdDB[],int choice)
{
int count = 0;
naive_sort (cdDB, datasize, & count);
if(choice == 5)
printf("\nCritical count is : %d\n",count);
else
printf("Array has been sorted");
printf("Press Enter To Continue");
fflush(stdin);
getch();
}
```

neone know how i can implement this for the quicksort coding shown above !!

Also does neone know how u can output data ontoa excel spreadsheet??

apreciate all help!!

u all been a great help in recent days!!