Here you can find the source of quickSort(double[] array, int low, int high)
Parameter | Description |
---|---|
array | The array to sort. |
low | Ending datasetIndex of the part of the array to sort. |
public static void quickSort(double[] array, int low, int high)
//package com.java2s; //License from project: Open Source License public class Main { /**//from w w w .j av a 2s . co m * Quicksort filter. Use low = 0 and high = length - 1 to sort the whole * array. From <a href= * "http://www.vogella.com/articles/JavaAlgorithmsQuicksort/article.html" * >http://www.vogella.com/articles/JavaAlgorithmsQuicksort/article.html<a> * * @param array The array to sort. * @param low Starting datasetIndex of the part of the array to sort. * @param low Ending datasetIndex of the part of the array to sort. */ public static void quickSort(double[] array, int low, int high) { int i = low, j = high; // Get the pivot element from the middle of the list double pivot = array[low + (high - low) / 2]; // Divide into two lists double exchange; while (i <= j) { // If the current value from the left list is smaller then the pivot // element then get the next element from the left list while (array[i] < pivot) { i++; } // If the current value from the right list is larger then the pivot // element then get the next element from the right list while (array[j] > pivot) { j--; } // If we have found a values in the left list which is larger then // the pivot element and if we have found a value in the right list // which is smaller then the pivot element then we exchange the // values. // As we are done we can increase i and j if (i <= j) { exchange = array[i]; array[i] = array[j]; array[j] = exchange; i++; j--; } } // Recursion if (low < j) quickSort(array, low, j); if (i < high) quickSort(array, i, high); } }