See More

// Java implementation of Counting Sort class CountingSort { void sort(char arr[]) { int n = arr.length; // The output character array that will have sorted arr char output[] = new char[n]; // Create a count array to store count of inidividul // characters and initialize count array as 0 int count[] = new int[256]; for (int i=0; i<256; ++i) count[i] = 0; // store count of each character for (int i=0; i=0; i--) { output[count[arr[i]]-1] = arr[i]; --count[arr[i]]; } // Copy the output array to arr, so that arr now // contains sorted characters for (int i = 0; i