fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. void swap(float *a,float *b)
  5. {
  6. float temp=*a;
  7. *a=*b;
  8. *b=temp;
  9. }
  10. int genmass(float* fArr, int fsize, int fleft, int fright)
  11. {
  12. fright = fright - fleft + 1;
  13. for (int i = 0; i<fsize; i++)
  14. {
  15. fArr[i] = rand() % fright + fleft;
  16. fArr[i] = fArr[i]/1000;
  17. }
  18. return 1;
  19. }
  20. float quick (float* Arr, int size, int lb, int rb);
  21. float quick (float* Arr, int size, int lb, int rb)
  22. {
  23.  
  24. int lc=lb;
  25. int rc=rb;
  26. float mid=0;
  27. for(int i=lb; i<rb;i++)
  28. mid = mid+Arr[i];
  29. mid=mid/(rc-lc+1);
  30. //mid=Arr[(lc+rc)/2];
  31. while(lc<=rc)
  32. {
  33. while(Arr[lc] < mid) lc++;
  34. while(Arr[rc] > mid) rc--;
  35. if(lc <= rc)
  36. {
  37. swap(&Arr[lc], &Arr[rc]);
  38. lc++;
  39. rc--;
  40. }
  41. }
  42. if (lc<rb)
  43. quick(Arr, size, lc, rb);
  44. if (lb<rc)
  45. quick(Arr, size, lb, rc);
  46. return 1;
  47. }
  48. int main() {
  49. float *Arr1 = new float[100000];
  50. genmass(Arr1, 10, 0, 100000);
  51. quick (Arr1, 1000, 0, 999);
  52. delete[] Arr1;// your code goes here
  53. return 0;
  54. }
Runtime error #stdin #stdout 0.54s 1531904KB
stdin
Standard input is empty
stdout
Standard output is empty