Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void QuickSortClassic<T>(IList<T> collection, int startIndex, int endIndex) where T : IComparable
- {
- if (startIndex >= endIndex)
- {
- return;
- }
- int pivotIndex = Partition(collection, startIndex, endIndex);
- QuickSortClassic(collection, startIndex, pivotIndex - 1);
- QuickSortClassic(collection, pivotIndex + 1, endIndex);
- }
- public static int Partition<T>(IList<T> collection, int startIndex, int endIndex) where T : IComparable
- {
- int pivotIndex = startIndex;
- var pivotValue = collection[endIndex];
- for (int i = startIndex; i < endIndex; i++)
- {
- if (collection[i].CompareTo(pivotValue) == -1 || collection[i].CompareTo(pivotValue) == 0)
- {
- Swap(collection, i, pivotIndex);
- pivotIndex++;
- }
- }
- Swap(collection, pivotIndex, endIndex);
- return pivotIndex;
- }
Advertisement
Add Comment
Please, Sign In to add comment