#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void quick(int *, int, int);
#define N 10
int main(void){
int a[N] = {0};
int k = 0;
for (k = 0; k < N ; k++) {
}
for (k = 0; k < N; k++) {
}
quick(a, 0, N - 1);
for (k = 0; k < N; k++) {
}
}
void check(int a[], int left, int right, int p, int center) {
int i = 0;
printf("(%d, %d) pivot: %d, center: %d\n", left
, right
, p
, center
); for (i = 0; i < N; i++) {
}
}
int pivot(int a[], int left, int right) {
return left;
}
int swap(int *x, int *y) {
int t = *x;
*x = *y;
*y = t;
}
int partition(int a[], int left, int right, int p) {
int i=left,j=right;
while(i<=j){
while(i<=right && a[i]<p) i++;
while(j>=left && a[j]>p) j--;
if(i<=j){
swap(&a[i],&a[j]);
i++;
j--;
}
}
return i;
}
void quick(int a[], int left, int right) {
if(left>=right) return;
int p = pivot(a, left, right);
int center = partition(a, left, right, a[p]);
check(a, left, right, p, center);
quick(a, left, center-1);
quick(a, center, right);
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KI2luY2x1ZGUgPHRpbWUuaD4KCnZvaWQgcXVpY2soaW50ICosIGludCwgaW50KTsKCiNkZWZpbmUgTiAxMAoKCmludCAgbWFpbih2b2lkKXsKCWludCBhW05dID0gezB9OwoJaW50IGsgPSAwOwoKCWZvciAoayA9IDA7IGsgPCBOIDsgaysrKSB7CgkJcHJpbnRmKCJJbnB1dCBhIG51bWJlcjogIik7CgkJc2NhbmYoIiVkIiwgJmFba10pOwoJfQoKCXByaW50ZigiYmVmb3JlOiAiKTsKCWZvciAoayA9IDA7IGsgPCBOOyBrKyspIHsKCQlwcmludGYoIiU0ZCIsIGFba10pOwoJfQoJcHJpbnRmKCJcbiIpOwoKCXF1aWNrKGEsIDAsIE4gLSAxKTsKCQoJcHJpbnRmKCJhZnRlcjogICIpOwoJZm9yIChrID0gMDsgayA8IE47IGsrKykgewoJCXByaW50ZigiJTRkIiwgYVtrXSk7Cgl9CglwcmludGYoI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GEsIGNlbnRlciwgcmlnaHQpOwoKfQoK
Input a number: Input a number: Input a number: Input a number: Input a number: Input a number: Input a number: Input a number: Input a number: Input a number: before: 0 0 0 0 0 0 0 0 0 0
(0, 9) pivot: 0, center: 5
0 0 0 0 0 0 0 0 0 0
(0, 4) pivot: 0, center: 3
0 0 0 0 0 0 0 0 0 0
(0, 2) pivot: 0, center: 2
0 0 0 0 0 0 0 0 0 0
(0, 1) pivot: 0, center: 1
0 0 0 0 0 0 0 0 0 0
(3, 4) pivot: 3, center: 4
0 0 0 0 0 0 0 0 0 0
(5, 9) pivot: 5, center: 8
0 0 0 0 0 0 0 0 0 0
(5, 7) pivot: 5, center: 7
0 0 0 0 0 0 0 0 0 0
(5, 6) pivot: 5, center: 6
0 0 0 0 0 0 0 0 0 0
(8, 9) pivot: 8, center: 9
0 0 0 0 0 0 0 0 0 0
after: 0 0 0 0 0 0 0 0 0 0