Java Array Sort countingSort(int[] array, int low, int high)

Here you can find the source of countingSort(int[] array, int low, int high)

Description

counting Sort

License

Open Source License

Declaration

public static void countingSort(int[] array, int low, int high) 

Method Source Code

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

import java.util.*;

public class Main {
    public static void countingSort(int[] array, int low, int high) {
        int[] counts = new int[high - low + 1]; // this will hold all possible values, from low to high
        for (int x : array)
            counts[x - low]++; // - low so the lowest possible value is always 0
        int current = 0;
        for (int i = 0; i < counts.length; i++) {
            Arrays.fill(array, current, current + counts[i], i + low); // fills counts[i] elements of value i + low in current
            current += counts[i]; // leap forward by counts[i] steps
        }/*from ww  w  .  j a v  a  2 s . co  m*/
    }
}

Related

  1. collectionToSortedArray(Collection objects)
  2. copyAndSort(String[] input)
  3. copyAndSort(T[] builtinFunctions)
  4. copySortArray(String[] values)
  5. countingSort(int[] a, int low, int high)
  6. deltaMetricToSortedIndicies( final double[][] deltaMetric)
  7. difference(int[] sorted1, int[] sorted2)
  8. extractFields(String[] items, int[] fields, String delim, boolean sortKeyFields)
  9. getLeftIndex(float[] sorted, float value)