This is an earlier version. Hoare is the name of the person. The partition () function in this version is different from the current one. I think this old version is not as easy to understand as the current version. It may seem easy to understand on the big aspect, but it is very troublesome to consider pointer movement when writing code.
# Include <string. h> # include <time. h> # define buffer_size 10int hoarepartition (int * a, int P, int R) {int TMP = 0; int I = 0; Int J = 0; int x = 0; I = P; j = r; X = A [p]; while (1) {While (A [J]> X) {J --;} while (A [I] <X) {I ++;} if (I <j) {TMP = A [I]; A [I] = A [J]; A [J] = TMP;} else {return I ;}} void hoarequicksort (int * a, int P, int R) {int q = 0; if (P <r) {q = hoarepartition (A, P, R); hoarequicksort (A, P, q-1); hoarequicksort (A, q + 1, R );}} int main () {int I = 0; Int J = 0; int A [buffer_size]; // randomly generated array srand (unsigned) Time (null )); for (j = 0; j <buffer_size; j ++) {A [J] = rand () % 100;} printf ("randomly generated array: \ n "); for (I = 0; I <buffer_size; I ++) {printf ("% d", a [I]);} printf ("\ n "); hoarequicksort (A, 0, BUFFER_SIZE-1); printf ("Sort arrays quickly: \ n"); for (I = 0; I <buffer_size; I ++) {printf ("% d", a [I]);} system ("pause"); Return 0 ;}