fork download
  1. using System;
  2.  
  3. public class Test
  4. {
  5. public static void Main()
  6. {
  7. int[] sortMe = { 2, 5, 6, 4, 8, 9, 6, 3, 21, 2, 5, 4, 8, 9, 6, 5, 46, 6, 3 };
  8. QuickSort(sortMe, 0, sortMe.Length - 1);
  9.  
  10. foreach (var item in sortMe)
  11. Console.Write(item + " ");
  12. }
  13.  
  14. private static void QuickSort(int[] sort, int first, int last)
  15. {
  16. int i = first;
  17. int j = last;
  18. int pivot = first;
  19. int temp;
  20.  
  21. while (i <= j)
  22. {
  23. while (sort[i] < sort[pivot]) { i++; }
  24. while (sort[j] > sort[pivot]) { j--; }
  25.  
  26. if (i <= j)
  27. {
  28. temp = sort[i];
  29. sort[i] = sort[j];
  30. sort[j] = temp;
  31. i++;
  32. j--;
  33. }
  34.  
  35. }
  36.  
  37. if (first < j) QuickSort(sort, first, j);
  38. if (last > i) QuickSort(sort, i, last);
  39. }
  40. }
Success #stdin #stdout 0.03s 33880KB
stdin
Standard input is empty
stdout
2 2 3 3 4 4 5 5 5 6 6 6 6 8 8 9 9 21 46