2 * Jalview - A Sequence Alignment Editor and Viewer (Development Version 2.4.1)
3 * Copyright (C) 2009 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
21 public class QuickSort
23 public static void sort(int[] arr, Object[] s)
25 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);
77 public static void sort(int[] arr, int p, int r, Object[] s)
83 q = partition(arr, p, r, s);
85 sort(arr, q + 1, r, s);
89 private static int partition(float[] arr, int p, int r, Object[] s)
100 } while (arr[j] > x);
105 } while (arr[i] < x);
124 private static int partition(int[] arr, int p, int r, Object[] s)
135 } while (arr[j] > x);
140 } while (arr[i] < x);
159 private static int partition(double[] arr, int p, int r, Object[] s)
170 } while (arr[j] > x);
175 } while (arr[i] < x);
194 private static int stringPartition(String[] arr, int p, int r, Object[] s)
205 } while (arr[j].compareTo(x) < 0);
210 } while (arr[i].compareTo(x) > 0);