fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4.  
  5. void Swap_Me(int *first, int *second)
  6. {
  7. int tmp = *first;
  8. *first = *second;
  9. *second = tmp;
  10. }
  11.  
  12. void Sort_Quick(int *data, int low, int high)
  13. {
  14. int i = low,
  15. j = high,
  16. x = data[(low + high) / 2];
  17.  
  18. do
  19. {
  20. while(data[i] < x) i++;
  21. while(data[j] > x) j--;
  22.  
  23. if(i <= j)
  24. {
  25. Swap_Me(&data[i], &data[j]);
  26. i++;
  27. j--;
  28. }
  29.  
  30. } while(i <= j);
  31.  
  32. if(low < j) Sort_Quick(data, low, j);
  33. if(i < high) Sort_Quick(data, i, high);
  34. }
  35.  
  36. void Array_Print(int *data, int size)
  37. {
  38. for(int i = 0; i < size; i++)
  39. {
  40. printf("[%i]: %i\r\n", i , data[i]);
  41. }
  42. }
  43.  
  44. int Init(int **data)
  45. {
  46. srand((unsigned int)time(NULL));
  47.  
  48. int size = rand();
  49. *data = (int*)malloc(size * sizeof(int));
  50.  
  51. for(int i = 0; i < size; i++)
  52. {
  53. *data[i] = rand();
  54. }
  55.  
  56. return size;
  57. }
  58.  
  59. int main(void)
  60. {
  61. srand((unsigned int)time(NULL));
  62. int array_length = rand();
  63. int *data = (int*)malloc(array_length * sizeof(int));
  64.  
  65. for(int i = 0; i < array_length; i++)
  66. {
  67. data[i] = rand();
  68. }
  69.  
  70. Array_Print(data, array_length);
  71. Sort_Quick(data, 0, --array_length);
  72. Array_Print(data, array_length);
  73.  
  74. return 0;
  75. }
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout

Standard output is empty