Quick sort program in java taking first element as pivot

Quick sort program in java taking first element as pivot. Quicksort is a programming language written in Java. It works by picking a ‘pivot’ element from the array and partitioning the remaining elements into two subarrays based on whether they are  greater or less than the pivot.

import java.util.Arrays;
class Main 
{
int a(int array[], int low, int high)
{
int pivot = array[high];
int i = (low - 1);
for (int j = low; j < high; j++) 
{
if (array[j] <= pivot)
{
i++;
int temp = array[i];
array[i] = array[j];
array[j] = temp;
}
}
int temp = array[i + 1];
array[i + 1] = array[high];
array[high] = temp;
return (i + 1);
}
void quickSort(int array[], int low, int high) {
if (low < high) 
{
int pi = a(array, low, high);
quickSort(array, low, pi - 1);
quickSort(array, pi + 1, high);
}
}
public static void main(String args[]) 
{
int[] data = { 56,787,343,456,987,111};
int size = data.length;
Main qs = new Main();
qs.quickSort(data, 0, size - 1);
System.out.println("After sorting");
System.out.println(Arrays.toString(data));
}
}

 

Output:

After sorting                                                                                                                    [56, 111, 343, 456, 787, 987]