Java Array Sort sortInterval(byte[] x, int start, int end)

Here you can find the source of sortInterval(byte[] x, int start, int end)

Description

sort Interval

License

Open Source License

Declaration

static byte[] sortInterval(byte[] x, int start, int end) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    static byte[] sortInterval(byte[] x, int start, int end) {
        assert start <= end;
        assert end <= x.length;
        final byte[] result = x.clone();
        final int[] counter = new int[256];
        for (int i = start; i < end; i++) {
            final int b = unsigned(x[i]);
            counter[b]++;//www  . j  a  va 2 s .  co m
        }
        int index = start;
        for (int i = 0; i < 256; i++) {
            for (int j = 0; j < counter[i]; j++)
                result[index++] = (byte) i;
        }
        return result;
    }

    static int unsigned(byte b) {
        return b & 0xff;
    }
}

Related

  1. sortIndexesDescending(final double[] in)
  2. sortindices(double[] x)
  3. sortIndices(float[] main)
  4. sortInPlace(final double[] v, final int i, final int j)
  5. sortInPlace(int[] array)
  6. sortKeyValuePairs(long[] keys, double[] values, int startInd, int endInd)
  7. sortLeftRightAndCenter(double[] array, int[] index, int l, int r)
  8. sortMatrixRows(A[] matrix, Comparator comparator)
  9. sortMinMaxToMax(double[] min, double[] max)