2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.0b1)
3 * Copyright (C) 2014 The Jalview Authors
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/>.
17 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 public class QuickSort
23 public static void sort(int[] arr, Object[] s)
25 sort(arr, 0, arr.length - 1, s);
28 public static void sort(float[] arr, Object[] s)
30 sort(arr, 0, arr.length - 1, s);
33 public static void sort(double[] arr, Object[] s)
35 sort(arr, 0, arr.length - 1, s);
38 public static void sort(String[] arr, Object[] s)
40 stringSort(arr, 0, arr.length - 1, s);
43 public static void stringSort(String[] arr, int p, int r, Object[] s)
49 q = stringPartition(arr, p, r, s);
50 stringSort(arr, p, q, s);
51 stringSort(arr, q + 1, r, s);
55 public static void sort(float[] arr, int p, int r, Object[] s)
61 q = partition(arr, p, r, s);
63 sort(arr, q + 1, r, s);
67 public static void sort(double[] arr, int p, int r, Object[] s)
73 q = partition(arr, p, r, s);
75 sort(arr, q + 1, r, s);
79 public static void sort(int[] arr, int p, int r, Object[] s)
85 q = partition(arr, p, r, s);
87 sort(arr, q + 1, r, s);
91 private static int partition(float[] arr, int p, int r, Object[] s)
102 } while (arr[j] > x);
107 } while (arr[i] < x);
126 private static int partition(int[] arr, int p, int r, Object[] s)
137 } while (arr[j] > x);
142 } while (arr[i] < x);
161 private static int partition(double[] arr, int p, int r, Object[] s)
172 } while (arr[j] > x);
177 } while (arr[i] < x);
196 private static int stringPartition(String[] arr, int p, int r, Object[] s)
207 } while (arr[j].compareTo(x) < 0);
212 } while (arr[i].compareTo(x) > 0);