1 2 5 14 package org.jacorb.trading.client.util; 15 16 17 public class QuickSort 18 { 19 private QuickSort() 20 { 21 } 22 23 24 public static void sort(String [] arr) 25 { 26 sortImpl(arr, 0, arr.length - 1); 27 } 28 29 30 protected static void sortImpl(String [] arr, int l, int h) 31 { 32 int low = l; 33 int hi = h; 34 String mid; 35 36 if (h > l) { 37 mid = arr[(l + h) / 2]; 38 39 while (low <= hi) { 40 while (low < h && arr[low].compareTo(mid) < 0) 41 low += 1; 42 43 while (hi > l && arr[hi].compareTo(mid) > 0) 44 hi -= 1; 45 46 if (low <= hi) { 47 String tmp = arr[low]; 48 arr[low] = arr[hi]; 49 arr[hi] = tmp; 50 51 low += 1; 52 hi -= 1; 53 } 54 } 55 56 if (l < hi) 57 sortImpl(arr, l, hi); 58 59 if (low < h) 60 sortImpl(arr, low, h); 61 } 62 } 63 } 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | Popular Tags |