[Go to site: main page, start]

0% found this document useful (0 votes)
7 views1 page

Quick Sort Java

The document contains a Java implementation of the QuickSort algorithm, which includes a partitioning method and a recursive quickSort method. The main function initializes an array, sorts it using quickSort, and prints the sorted array. The program effectively demonstrates the sorting of an integer array using the QuickSort technique.

Uploaded by

123456bca987
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views1 page

Quick Sort Java

The document contains a Java implementation of the QuickSort algorithm, which includes a partitioning method and a recursive quickSort method. The main function initializes an array, sorts it using quickSort, and prints the sorted array. The program effectively demonstrates the sorting of an integer array using the QuickSort technique.

Uploaded by

123456bca987
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Java Sorting Program

public class QuickSort {


public static 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 temp = arr[i + 1];
arr[i + 1] = arr[high];
arr[high] = temp;
return i + 1;
}

public static void 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);
}
}

public static void main(String[] args) {


int[] arr = {10, 7, 8, 9, 1, 5};
quickSort(arr, 0, [Link] - 1);
for (int num : arr) {
[Link](num + " ");
}
}
}

You might also like