Here you can find the source of sort(String[] s)
Parameter | Description |
---|---|
s | strings to be alphabetized } |
public static void sort(String[] s)
//package com.java2s; //License from project: Apache License public class Main { /**{ method//from w w w. ja v a 2 s . c o m @name sort @function - alphabetize an array of strings in place using heapsort @param s strings to be alphabetized }*/ public static void sort(String[] s) { if (s == null || s.length < 2) { return; } int l, j, ir, i; String rra; String[] ra = new String[s.length + 1]; for (int ix = 0; ix < s.length; ix++) ra[ix + 1] = s[ix]; // now run the heap sort l = (s.length >> 1) + 1; ir = s.length; for (;;) { if (l > 1) { rra = ra[--l]; } else { rra = ra[ir]; ra[ir] = ra[1]; if (--ir == 1) { ra[1] = rra; break; } } i = l; j = l << 1; while (j <= ir) { if (j < ir && ra[j].compareTo(ra[j + 1]) < 0) { ++j; } if (rra.compareTo(ra[j]) < 0) { ra[i] = ra[j]; j += (i = j); } else { j = ir + 1; } } ra[i] = rra; } for (int ix = 0; ix < s.length; ix++) s[ix] = ra[ix + 1]; } }