gistlib
main.cspublic static void QuickSort(int[] arr, int left, int right) { if (left < right) { int pivotIndex = Partition(arr, left, right); QuickSort(arr, left, pivotIndex - 1); QuickSort(arr, pivotIndex + 1, right); } } private static int Partition(int[] arr, int left, int right) { int pivot = arr[right]; int i = left; for (int j = left; j < right; j++) { if (arr[j] < pivot) { int temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; i++; } } int temp2 = arr[i]; arr[i] = arr[right]; arr[right] = temp2; return i; } 652 chars34 lines
public static void QuickSort(int[] arr, int left, int right) { if (left < right) { int pivotIndex = Partition(arr, left, right); QuickSort(arr, left, pivotIndex - 1); QuickSort(arr, pivotIndex + 1, right); } } private static int Partition(int[] arr, int left, int right) { int pivot = arr[right]; int i = left; for (int j = left; j < right; j++) { if (arr[j] < pivot) { int temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; i++; } } int temp2 = arr[i]; arr[i] = arr[right]; arr[right] = temp2; return i; }
Explanation:
QuickSort
Partition
gistlibby LogSnag