- #1

cubanmissile

- 5

- 0

## Homework Statement

Function:

Code:

```
void quickSort(struct student *array, int start, int end) {
int i = start;
int j = end;
while(i < j) {
// Move left counter, then right counter.
while(i <= end && array[i].numDays <= array[start].numDays)
i++;
while(array[j].numDays > array[start].numDays)
j--;
if(i < j)
swap(array, i, j);
}
swap(array, start, j);
if(array[j].numDays < array[start].numDays)
quickSort(array, 0, j);
if(array[j].numDays > array[end].numDays)
quickSort(array, j, end);
}
```

## Homework Equations

None

## The Attempt at a Solution

I have tried many different versions. Changing the variables from array[j] to array

*> array[start], as well as changing the bottom statement. This doesn't correctly sort the array however... Is there something I am missing? Look at this, I would *assume* it would work.*

Here's why:

First, it increases the left index...then the right. Once all that's done and the elements are swapped, it checks to see if the element on the right index is larger than the element at the left index. If so, run quickSort again. Then after that recursive call, it then checks to the right of the partition element. If it's larger than the end element, recursively call until it is not.

So, why would it not be working?

Here's why:

First, it increases the left index...then the right. Once all that's done and the elements are swapped, it checks to see if the element on the right index is larger than the element at the left index. If so, run quickSort again. Then after that recursive call, it then checks to the right of the partition element. If it's larger than the end element, recursively call until it is not.

So, why would it not be working?