1 package org.apache.lucene.util; 2 3 56 57 59 68 69 public class Arrays { 70 93 public static void sort(String [] a) { 94 String aux[] = (String [])a.clone(); 95 mergeSort(aux, a, 0, a.length); 96 } 97 98 private static void mergeSort(String src[], String dest[], 99 int low, int high) { 100 int length = high - low; 101 102 if (length < 7) { 104 for (int i=low; i<high; i++) 105 for (int j=i; j>low && (dest[j-1]).compareTo(dest[j])>0; j--) 106 swap(dest, j, j-1); 107 return; 108 } 109 110 int mid = (low + high)/2; 112 mergeSort(dest, src, low, mid); 113 mergeSort(dest, src, mid, high); 114 115 if ((src[mid-1]).compareTo(src[mid]) <= 0) { 118 System.arraycopy(src, low, dest, low, length); 119 return; 120 } 121 122 for(int i = low, p = low, q = mid; i < high; i++) { 124 if (q>=high || p<mid && (src[p]).compareTo(src[q])<=0) 125 dest[i] = src[p++]; 126 else 127 dest[i] = src[q++]; 128 } 129 } 130 131 134 private static void swap(String x[], int a, int b) { 135 String t = x[a]; 136 x[a] = x[b]; 137 x[b] = t; 138 } 139 } 140 141 142 143 144 145 146 147 148 149 150 151 | Popular Tags |