2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ 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
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
24 * A class to perform efficient sorting of arrays of objects based on arrays of
25 * scores or other attributes. For example, residues by frequency.
30 public class QuickSort
33 * Sorts both arrays with respect to ascending order of the items in the first
39 public static void sort(int[] arr, Object[] s)
41 sort(arr, 0, arr.length - 1, s);
45 * Sorts both arrays with respect to ascending order of the items in the first
51 public static void sort(float[] arr, Object[] s)
53 sort(arr, 0, arr.length - 1, s);
57 * Sorts both arrays with respect to ascending order of the items in the first
63 public static void sort(double[] arr, Object[] s)
65 sort(arr, 0, arr.length - 1, s);
69 * Sorts both arrays with respect to descending order of the items in the
75 public static void sort(String[] arr, Object[] s)
77 stringSort(arr, 0, arr.length - 1, s);
80 static void stringSort(String[] arr, int p, int r, Object[] s)
86 q = stringPartition(arr, p, r, s);
87 stringSort(arr, p, q, s);
88 stringSort(arr, q + 1, r, s);
92 static void sort(float[] arr, int p, int r, Object[] s)
98 q = partition(arr, p, r, s);
100 sort(arr, q + 1, r, s);
104 static void sort(double[] arr, int p, int r, Object[] s)
110 q = partition(arr, p, r, s);
112 sort(arr, q + 1, r, s);
116 static void sort(int[] arr, int p, int r, Object[] s)
122 q = partition(arr, p, r, s);
124 sort(arr, q + 1, r, s);
128 static int partition(float[] arr, int p, int r, Object[] s)
139 } while (arr[j] > x);
144 } while (arr[i] < x);
163 static int partition(int[] arr, int p, int r, Object[] s)
174 } while (arr[j] > x);
179 } while (arr[i] < x);
198 static int partition(double[] arr, int p, int r, Object[] s)
209 } while (arr[j] > x);
214 } while (arr[i] < x);
233 static int stringPartition(String[] arr, int p, int r, Object[] s)
244 } while (arr[j].compareTo(x) < 0);
249 } while (arr[i].compareTo(x) > 0);