Advertisement
Guest User

Говнокод

a guest
Apr 29th, 2019
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.04 KB | None | 0 0
  1.  public int[] quickSort(int[] needSort)
  2.         {
  3.            
  4.             if (needSort.Length < 2)
  5.             {
  6.                 return needSort;
  7.             }
  8.  
  9.             int marker = needSort[needSort.Length / 2];
  10.             List<int> right = new List<int>();
  11.             List<int> left = new List<int>();
  12.             for (int i = 0; i < needSort.Length; i++)
  13.             {
  14.                 if (needSort[i] >= marker)
  15.                 {
  16.                     right.Add(needSort[i]);
  17.                 }
  18.                 else
  19.                 {
  20.                     left.Add(needSort[i]);
  21.                 }
  22.             }
  23.  
  24.             int[] arrRight = right.ToArray();
  25.             int[] arrLeft = left.ToArray();
  26.             int[] arrMarker = new int[1];
  27.             arrMarker[0] = marker;
  28.  
  29.             arrRight = quickSort(arrRight);
  30.             arrLeft = quickSort(arrLeft);
  31.             arrLeft = arrLeft.Concat(arrMarker).ToArray();
  32.             needSort = arrLeft.Concat(arrRight).ToArray();
  33.             return needSort;
  34.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement