Created
June 21, 2024 00:26
-
-
Save hsynkrcf/a8cea1c13e82134d49a4ae53b5cf11d6 to your computer and use it in GitHub Desktop.
Quick Sort Algorithm Performed On C#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public int[] QuickSort(int[] arr, int low, int high) | |
{ | |
if (low < high) | |
{ | |
int pi = Partition(arr, low, high); | |
QuickSort(arr, low, pi - 1); | |
QuickSort(arr, pi + 1, high); | |
} | |
return arr; | |
} | |
private int Partition(int[] arr, int low, int high) | |
{ | |
int pivot = arr[high]; | |
int i = (low - 1); | |
for (int j = low; j < high; j++) | |
{ | |
if (arr[j] < pivot) | |
{ | |
i++; | |
int temp = arr[i]; | |
arr[i] = arr[j]; | |
arr[j] = temp; | |
} | |
} | |
int temp1 = arr[i + 1]; | |
arr[i + 1] = arr[high]; | |
arr[high] = temp1; | |
return i + 1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment