Java Array Sort sort(String[] s)

Here you can find the source of sort(String[] s)

Description

{ method

License

Apache License

Parameter

Parameter Description
s strings to be alphabetized }

Declaration

public static void sort(String[] s) 

Method Source Code

//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];
    }
}

Related

  1. sort(Object[] array, Comparator comparator)
  2. sort(Object[] array, int start, int end)
  3. sort(Object[] array_, boolean accendingOrder_)
  4. sort(String a[])
  5. sort(String[] colnos)
  6. sort(String[] sArray)
  7. sort(String[] str)
  8. sort(String[] strArray)
  9. sort(String[] strArray)