Here you can find the source of countingSort(int[] a, int low, int high)
public static void countingSort(int[] a, int low, int high)
//package com.java2s; //License from project: Apache License import java.util.Arrays; public class Main { /**/*from w ww . j av a2 s . c om*/ * Counting sort that sorts the integer array in O(n+k) where n is the number * of elements and k is the length of the integer intervals given (high - * low). So you can imagine that it uses domain knowledge of the contained * integers, like the lowest value and the highest. It only works for positive * numbers, so please don't come up with negative numbers, it will result in * array out of bound exceptions, since they don't have an array index. */ public static void countingSort(int[] a, int low, int high) { final int[] counts = new int[high - low + 1]; for (int x : a) { counts[x - low]++; } int current = 0; for (int i = 0; i < counts.length; i++) { Arrays.fill(a, current, current + counts[i], i + low); current += counts[i]; } } }