注意,本文不是字符串排序,是字符串数组的排序。

方法分别是:
1、低位优先键索引排序
2、高位优先建索引排序
3、Java自带排序(经过调优的归并排序)
4、冒泡排序
5、快速排序
6、三向快速排序
时间复杂度:
本文中使用的例子是一个5757行的随机字符串数组文本TXT,实际测试结果:
稳定的排序是:
低位优先:
public static void sort(String[] a, int w) {
int n = a.length;
int R = 256; // extend ASCII alphabet size
String[] aux = new String[n];
for (int d = w-1; d >= 0; d--) {
int[] count = new int[R+1];
for (int i = 0; i < n; i++)
count[a[i].charAt(d) + 1]++;
for (int r = 0; r < R; r++)
count[r+1] += count[r];
for (int i = 0; i < n; i++)
aux[count[a[i].charAt(d)]++] = a[i];
for (int i = 0; i < n; i++)
a[i] = aux[i];
}
}
另外有需要云服务器可以了解下创新互联建站www.cdcxhl.com,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。