برنامه ای به زبان جاوا که الگوریتم مرتب سازی سریع یا همان Quick Sort را بر روی آرایه پیاده می کند.
/* Program: Quick Sort Version: 1.0 | 19 June 2016 Language: Java Programmer: Sina Moradi E-mail: Moradix96@gmail.com Website: http://www.Samiantec.ir */ package quicksort; public class QuickSort { public static void main(String[] args) { int[] a = { 3, 4, 5, 2, 1 }; quickSort(a, 0, a.length - 1); System.out.print("Sorted Result: "); print(a); } public static void quickSort(int[] array, int low, int high) { if (low < high) { System.out.print("Do partition from " + low + " to " + high + " in : "); print(array); int p = partition(array, low, high); quickSort(array, low, p); quickSort(array, p + 1, high); } } public static int partition(int[] array, int left, int right) { int i = left; int j = right - 1; int pivot = array[right]; while (i < j) { while (array[i] < pivot && i < j) { i++; } while (array[j] > pivot && i < j) { j--; } int t = array[i]; array[i] = array[j]; array[j] = t; } int t = array[i]; if (t > pivot) { array[i] = pivot; array[right] = t; } return i; } public static void print(int[] array) { for (int i: array) { System.out.print(i + " "); } System.out.println(); } }