2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)
3 * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, G Barton, M Clamp, S Searle
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
20 public class QuickSort
22 public static void sort(int[] arr, Object[] s)
24 sort(arr, 0, arr.length - 1, s);
27 public static void sort(float[] arr, Object[] s)
29 sort(arr, 0, arr.length - 1, s);
32 public static void sort(double[] arr, Object[] s)
34 sort(arr, 0, arr.length - 1, s);
37 public static void sort(String[] arr, Object[] s)
39 stringSort(arr, 0, arr.length - 1, s);
42 public static void stringSort(String[] arr, int p, int r, Object[] s)
48 q = stringPartition(arr, p, r, s);
49 stringSort(arr, p, q, s);
50 stringSort(arr, q + 1, r, s);
54 public static void sort(float[] arr, int p, int r, Object[] s)
60 q = partition(arr, p, r, s);
62 sort(arr, q + 1, r, s);
66 public static void sort(double[] arr, int p, int r, Object[] s)
72 q = partition(arr, p, r, s);
74 sort(arr, q + 1, r, s);
78 public static void sort(int[] arr, int p, int r, Object[] s)
84 q = partition(arr, p, r, s);
86 sort(arr, q + 1, r, s);
90 private static int partition(float[] arr, int p, int r, Object[] s)
101 } while (arr[j] > x);
106 } while (arr[i] < x);
125 private static int partition(int[] arr, int p, int r, Object[] s)
136 } while (arr[j] > x);
141 } while (arr[i] < x);
160 private static int partition(double[] arr, int p, int r, Object[] s)
171 } while (arr[j] > x);
176 } while (arr[i] < x);
195 private static int stringPartition(String[] arr, int p, int r, Object[] s)
206 } while (arr[j].compareTo(x) < 0);
211 } while (arr[i].compareTo(x) > 0);