#include <iostream>
using namespace std;
void swap(float *a,float *b)
{
float temp=*a;
*a=*b;
*b=temp;
}
int genmass(float* fArr, int fsize, int fleft, int fright)
{
fright = fright - fleft + 1;
for (int i = 0; i<fsize; i++)
{
fArr[i] = rand() % fright + fleft;
fArr[i] = fArr[i]/1000;
}
return 1;
}
float quick (float* Arr, int size, int lb, int rb);
float quick (float* Arr, int size, int lb, int rb)
{
int lc=lb;
int rc=rb;
float mid=0;
for(int i=lb; i<rb;i++)
mid = mid+Arr[i];
mid=mid/(rc-lc+1);
//mid=Arr[(lc+rc)/2];
while(lc<=rc)
{
while(Arr[lc] < mid) lc++;
while(Arr[rc] > mid) rc--;
if(lc <= rc)
{
swap(&Arr[lc], &Arr[rc]);
lc++;
rc--;
}
}
if (lc<rb)
quick(Arr, size, lc, rb);
if (lb<rc)
quick(Arr, size, lb, rc);
return 1;
}
int main() {
float *Arr1 = new float[100000];
genmass(Arr1, 10, 0, 100000);
quick (Arr1, 1000, 0, 999);
delete[] Arr1;// your code goes here
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKdm9pZCBzd2FwKGZsb2F0ICphLGZsb2F0ICpiKQp7CglmbG9hdCB0ZW1wPSphOwoJKmE9KmI7CgkqYj10ZW1wOwp9CmludCBnZW5tYXNzKGZsb2F0KiBmQXJyLCBpbnQgZnNpemUsIGludCBmbGVmdCwgaW50IGZyaWdodCkgCnsgCmZyaWdodCA9IGZyaWdodCAtIGZsZWZ0ICsgMTsgCmZvciAoaW50IGkgPSAwOyBpPGZzaXplOyBpKyspIAp7CmZBcnJbaV0gPSByYW5kKCkgJSBmcmlnaHQgKyBmbGVmdDsgCmZBcnJbaV0gPSBmQXJyW2ldLzEwMDA7Cn0KcmV0dXJuIDE7IAp9CmZsb2F0IHF1aWNrIChmbG9hdCogQXJyLCBpbnQgc2l6ZSwgaW50IGxiLCBpbnQgcmIpOwpmbG9hdCBxdWljayAoZmxvYXQqIEFy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