You are viewing a single comment's thread. Return to all comments →
void quickSort(int *a, int size){ if(size > 1){ int temp, pivot = a[0], b = size-1; for(int i = size-1; i >= 0; i--){ if(a[i] >= pivot){ temp = a[i]; int j = i; while(j < b){ a[j] = a[j+1]; j++; } a[b--] = temp; } } b++; quickSort(a, b); quickSort(a+b+1, size-b-1); for(int i = 0; i < size; ++i){ printf("%d ", a[i]); } printf("\n"); } } int main(void) { int N; scanf("%d", &N); int a[N]; for(int i = 0; i < N; i++){ scanf("%d", &a[i]); } quickSort(a,N); return 0;
}
Seems like cookies are disabled on this browser, please enable them to open this website
Quicksort 2 - Sorting
You are viewing a single comment's thread. Return to all comments →
include
void quickSort(int *a, int size){ if(size > 1){ int temp, pivot = a[0], b = size-1; for(int i = size-1; i >= 0; i--){ if(a[i] >= pivot){ temp = a[i]; int j = i; while(j < b){ a[j] = a[j+1]; j++; } a[b--] = temp; } } b++; quickSort(a, b); quickSort(a+b+1, size-b-1); for(int i = 0; i < size; ++i){ printf("%d ", a[i]); } printf("\n"); } } int main(void) { int N; scanf("%d", &N); int a[N]; for(int i = 0; i < N; i++){ scanf("%d", &a[i]); } quickSort(a,N); return 0;
}