Here you can find the source of sortLeftRightAndCenter(double[] array, int[] index, int l, int r)
private static int sortLeftRightAndCenter(double[] array, int[] index, int l, int r)
//package com.java2s; /*/* w w w .j a v a2 s .com*/ * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ public class Main { /** * Sorts left, right, and center elements only, returns resulting center as pivot. */ private static int sortLeftRightAndCenter(double[] array, int[] index, int l, int r) { int c = (l + r) / 2; conditionalSwap(array, index, l, c); conditionalSwap(array, index, l, r); conditionalSwap(array, index, c, r); return c; } /** * Conditional swap for quick sort. */ private static void conditionalSwap(double[] array, int[] index, int left, int right) { if (array[index[left]] > array[index[right]]) { int help = index[left]; index[left] = index[right]; index[right] = help; } } }