#include <stdio.h> void QuickSort1 (int *s,int left,int right) {int. i,j,t,pivot;if (left>right) return;if (left <right) {pivot = s[left];//base number I=left;j=right;while (I!=j) {while (i<j &&s[j]>=pivot) j--;// From right to left, find the first number that is smaller than the base number while (I<j &&s[i]<=pivot) i++;//from left to right for the first number that is larger than the base number if (I<J)//Exchange two number {T=s[i];s[i]=s[j];s[j ]=t;}} S[left] = s[i];//datum number return s[i] = pivot; QuickSort1 (s,left,i-1); QuickSort1 (S,i+1,right);}} void QuickSort2 (int *s,int left,int right) {int i,j,pivot;if (left>right) return;if (left<right) {pivot = s[left];// Base number I=left;j=right;while (I!=j) {while (i<j &&s[j]>=pivot) j--;//Right-to-left find the first number less than the base number if (I<j) {S[i]=s[j];i ++;} while (I<j &&s[i]<=pivot) i++;//from left to right find the first number larger than the base number if (I<j) {s[j]=s[i];j--;}} S[i] = pivot;//Datum number QuickSort2 (s,left,i-1); QuickSort2 (S,i+1,right);}} int main () {int a[] = {8,6,12,10,2,7,3,15,9,20};//quicksort1 (a,0,9); QuickSort1 (a,0,9); int i=0;for (; i<10;i++) printf ("%d", a[i]); return 0;}
Learn Quick Sort again (C language)