#include <stdio.h> #pragma warning(disable:4996) void quicksort(int*, int, int); void printarr(int*, int, int); int main(void) { int arr1[10] = { 4, 2, 1, 5, 3, 6, 2, 5, 3, 0 }; int arr2[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; int arr3[10] = { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 }; int arr4[10] = { 0, 1, 1, 1, 0, 3, 2, 2, 1, 0 }; printarr(arr1, 0, 9); quicksort(arr1, 0, 9); printarr(arr1, 0, 9); printf("\n====================\n"); printarr(arr2, 0, 9); quicksort(arr2, 0, 9); printarr(arr2, 0, 9); printf("\n====================\n"); printarr(arr3, 0, 9); quicksort(arr3, 0, 9); printarr(arr3, 0, 9); printf("\n====================\n"); printarr(arr4, 0, 9); quicksort(arr4, 0, 9); printarr(arr4, 0, 9); printf("\n====================\n"); return 0; } void quicksort(int* arr, int s, int e) { if (e - s < 1) return; int k = s; int t = 0; for (int i = s + 1; i <= e; i++) { if (arr[s] > arr[i]) { t = arr[k + 1]; arr[k + 1] = arr[i]; arr[i] = t; k++; } } t = arr[k]; arr[k] = arr[s]; arr[s] = t; quicksort(arr, s, k - 1); quicksort(arr, k + 1, e); } void printarr(int* arr, int s, int e) { int i; printf("Printing array.... { "); for (i = s; i < e; i++) { printf("%d, ", arr[i]); } printf("%d }\n", arr[e]); }
#include <stdio.h> void quicksort(int*arr, int s, int e){ int pivot, i, j, t; if (e - s <= 1) return; pivot = arr[s]; int k = s; for (i = s + 1; i <= e; i++){ if (arr[s] > arr[i]){ t = arr[k + 1]; arr[k + 1] = arr[i]; arr[i] = t; k++; } } int a; a = arr[s]; arr[s] = arr[k]; arr[k] = a; quicksort(arr, s, k - 1); quicksort(arr, k + 1, e); } int main(void){ int arr[10] = { 100, 3, 139, 7, 9, 57, 4, 6, 8, 0 }; int i; quicksort(arr, 0, 9); for (i = 0; i <= 9; i++) printf("%d\n", arr[i]); return 0; }
#include<stdio.h> void quicksort(int* arr, int s, int e) { int i, t, pivot; int z; if (e - s < 1) { return; } int k = s; pivot = arr[s]; for (i = s + 1; i <= e; i++) { if (arr[s] > arr[i]) { t = arr[k + 1]; arr[k + 1] = arr[i]; arr[i] = t; k++; } } z = arr[s]; arr[s] = arr[k]; arr[k] = z; quicksort(arr, s, k - 1); quicksort(arr, k + 1, e); } int main() { int arr[10] = { 1, 3, 5, 22, 6, 12, 451, 64, 31, 777 }; quicksort(arr, 0, 9); for (int i = 0; i < 10; i++) { printf(" %d \n", arr[i]); } return 0; }
#include <stdio.h> void quicksort(int * arr, int s, int e) { int i,j,pivot,t; if(s>=e) return; pivot=s; for(i=s+1;i<=e;i++) { if(arr[s]>arr[i]) { pivot++; if(arr[i]<arr[pivot]) { t=arr[pivot]; arr[pivot]=arr[i]; arr[i]=t; } } } t=arr[pivot]; arr[pivot]=arr[s]; arr[s]=t; quicksort(arr,s,pivot-1); quicksort(arr,pivot+1,e); } int main() { int i; int arr[20]; for(i=0;i<=19;i++) scanf("%d",&arr[i]); quicksort(arr,0,19); for(i=0;i<=19;i++) printf("%d ",arr[i]); return 0; }