If you can help me, really thanks! Below is my code to sort vectors of numbers (of type double). The number of elements in vec is 200,000.
The program stopped at the green line, after several seconds. The error message is that
"Thread 1: EXC_BAD_ACCESS (code = 2, address=0x7fff5f3fffd8)".
just like the picture:
/*This is block to call quickSort*/
void VectorDoubleSort:: sort(std::vector<double>& vec){
int start = 0;
int end = vec.size() - 1;
quickSort(vec, start, end);
}
/*This block to fulfill the quickSort method*/
void VectorDoubleSort:: quickSort(std::vector<double>& vec, int start, int end)
{
int pivot = (start + end) / 2;
int smallIndex = start;
if (start < end) {
double tempA = vec[start];
vec[pivot] = tempA;
for (int i = start + 1; i <= end; i++) {
if (vec[i] <= vec[start]) {
smallIndex += 1;
double tempB = vec[i];
vec[i] = vec[smallIndex];
vec[smallIndex] = tempB;
}
}
double tempC = vec[start];
vec[start] = vec[smallIndex];
vec[smallIndex] = tempC;
pivot = smallIndex;
quickSort(vec, start, pivot - 1);
quickSort(vec, pivot + 1, end);
}
}