Here you can find the source of quickSort(int[] array)
Parameter | Description |
---|---|
array | a parameter |
public static void quickSort(int[] array)
//package com.java2s; //License from project: Apache License public class Main { /**//w w w . j av a 2s . co m * quick sort. * * @param array */ public static void quickSort(int[] array) { quickSort(array, 0, array.length); } private static void quickSort(int[] array, int start, int end) { int r = 0; if (start < end) { r = partition(array, start, end); quickSort(array, start, r - 1); quickSort(array, r + 1, end); } } private static int partition(int[] array, int q, int p) { int pivot = array[q]; int i = q; // through the loop, i always points to the end of the sub-array whose // element is <= pivot. for (int j = q + 1; j < p; j++) { if (array[j] < pivot) { i++; swap(array, i, j); } } swap(array, i, q); return i; } private static void swap(int[] array, int a, int b) { int temp = array[a]; array[a] = array[b]; array[b] = temp; } }