Skip to content

Instantly share code, notes, and snippets.

@olund
Created December 10, 2013 09:33
Show Gist options
  • Save olund/7888017 to your computer and use it in GitHub Desktop.
Save olund/7888017 to your computer and use it in GitHub Desktop.
void qsort(int array[], int end, int start = 0) {
int i=start, j = end;
int temp;
int pivot=array[(start+end)/2];
cout << "Sorterar från " << start << " till " << end << " pivot " << pivot << endl;
while (i <= j) {
while (array[i] < pivot) {
i++;
}
while (pivot < array[j]) {
j--;
}
if(i <= j) {
cout << "byter " << array[i] << " mot " << array[j] << endl;
temp = array[i];
array[i] = array[j];
array[j] = temp;
i++;
j--;
}
}
if(start < j) {
qsort(array, j, start);
}
if(i < end) {
qsort(array, end, i);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment