fork download
  1. using System;
  2.  
  3. unsafe class Program
  4. {
  5. //struct Header
  6. //{
  7. // internal int* data;
  8. //};
  9.  
  10. //Header* object_header = stackalloc Header[sizeof(Header)];
  11. //object_header->data = stackalloc int[length];
  12.  
  13. static void SwapMe(int* first, int* second)
  14. {
  15. int tmp = *first;
  16. *first = *second;
  17. *second = tmp;
  18. }
  19.  
  20. static void SortQuick(int* data, int low, int high)
  21. {
  22. int i = low,
  23. j = high,
  24. x = data[(low + high) / 2];
  25.  
  26. do
  27. {
  28. while (data[i] < x) i++;
  29. while (data[j] > x) j--;
  30.  
  31. if (i <= j)
  32. {
  33. SwapMe(&data[i], &data[j]);
  34. i++;
  35. j--;
  36. }
  37.  
  38. } while (i <= j);
  39.  
  40. if (low < j) SortQuick(data, low, j);
  41. if (j < high) SortQuick(data, j, high);
  42. }
  43.  
  44. static void ArrayPrint(int* data, int length)
  45. {
  46. for (int i = 0; i < length; i++)
  47. {
  48. Console.WriteLine(data[i]);
  49. }
  50. }
  51.  
  52. static void Main()
  53. {
  54. int length = new Random().Next(1000, 99999);
  55. int* data = stackalloc int[length];
  56. int capicity = length * sizeof(int);
  57.  
  58. for (int i = 0; i < capicity; i++)
  59. {
  60. data[i] = new Random().Next(0, 9999);
  61. }
  62.  
  63. ArrayPrint(data, capicity);
  64. SortQuick(data, 0, length - 1);
  65. ArrayPrint(data, capicity);
  66.  
  67. Console.ReadLine();
  68. }
  69. }
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty