2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
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
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.
23 public class QuickSort
25 public static void sort(int[] arr, Object[] s)
27 sort(arr, 0, arr.length - 1, s);
30 public static void sort(float[] arr, Object[] s)
32 sort(arr, 0, arr.length - 1, s);
35 public static void sort(double[] arr, Object[] s)
37 sort(arr, 0, arr.length - 1, s);
40 public static void sort(String[] arr, Object[] s)
42 stringSort(arr, 0, arr.length - 1, s);
45 public static void stringSort(String[] arr, int p, int r, Object[] s)
51 q = stringPartition(arr, p, r, s);
52 stringSort(arr, p, q, s);
53 stringSort(arr, q + 1, r, s);
57 public static void sort(float[] arr, int p, int r, Object[] s)
63 q = partition(arr, p, r, s);
65 sort(arr, q + 1, r, s);
69 public static void sort(double[] arr, int p, int r, Object[] s)
75 q = partition(arr, p, r, s);
77 sort(arr, q + 1, r, s);
81 public static void sort(int[] arr, int p, int r, Object[] s)
87 q = partition(arr, p, r, s);
89 sort(arr, q + 1, r, s);
93 private static int partition(float[] arr, int p, int r, Object[] s)
104 } while (arr[j] > x);
109 } while (arr[i] < x);
128 private static int partition(int[] arr, int p, int r, Object[] s)
139 } while (arr[j] > x);
144 } while (arr[i] < x);
163 private static int partition(double[] arr, int p, int r, Object[] s)
174 } while (arr[j] > x);
179 } while (arr[i] < x);
198 private static int stringPartition(String[] arr, int p, int r, Object[] s)
209 } while (arr[j].compareTo(x) < 0);
214 } while (arr[i].compareTo(x) > 0);