Skip to content

Instantly share code, notes, and snippets.

@hsynkrcf
Created June 21, 2024 00:26
Show Gist options
  • Save hsynkrcf/a8cea1c13e82134d49a4ae53b5cf11d6 to your computer and use it in GitHub Desktop.
Save hsynkrcf/a8cea1c13e82134d49a4ae53b5cf11d6 to your computer and use it in GitHub Desktop.
Quick Sort Algorithm Performed On C#
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