Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public int[] quickSort(int[] needSort)
- {
- if (needSort.Length < 2)
- {
- return needSort;
- }
- int marker = needSort[needSort.Length / 2];
- List<int> right = new List<int>();
- List<int> left = new List<int>();
- for (int i = 0; i < needSort.Length; i++)
- {
- if (needSort[i] >= marker)
- {
- right.Add(needSort[i]);
- }
- else
- {
- left.Add(needSort[i]);
- }
- }
- int[] arrRight = right.ToArray();
- int[] arrLeft = left.ToArray();
- int[] arrMarker = new int[1];
- arrMarker[0] = marker;
- arrRight = quickSort(arrRight);
- arrLeft = quickSort(arrLeft);
- arrLeft = arrLeft.Concat(arrMarker).ToArray();
- needSort = arrLeft.Concat(arrRight).ToArray();
- return needSort;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement