Skip to content

Instantly share code, notes, and snippets.

@syedjafer
Created April 30, 2021 10:58
Show Gist options
  • Select an option

  • Save syedjafer/e45839796c29fe1c72beab9e306f2720 to your computer and use it in GitHub Desktop.

Select an option

Save syedjafer/e45839796c29fe1c72beab9e306f2720 to your computer and use it in GitHub Desktop.
public class QSort{
static void printArray(int[] arr, int size)
{
for(int i = 0; i < size; i++)
System.out.print(arr[i] + " ");
System.out.println();
}
static int partition(int[] arr, int low, int high)
{
int pivot = arr[high];
int partition_index = low;
int temp ;
for(int itr = low; itr <= high - 1; itr++)
{
if (arr[itr] < pivot)
{
temp = arr[itr];
arr[itr] = arr[partition_index];
arr[partition_index] = temp;
partition_index += 1;
}
}
temp = arr[high];
arr[high] = arr[partition_index];
arr[partition_index] = temp;
return pivot;
}
public static void main(String []args){
int arr[] = {3, 8, 6, 2, 4, 7, 8, 5};
partition(arr, 0, 7);
printArray(arr, 8);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment