diff --git a/Sorting Algorithms/Countsort.java b/Sorting Algorithms/Countsort.java new file mode 100644 index 00000000..232df591 --- /dev/null +++ b/Sorting Algorithms/Countsort.java @@ -0,0 +1,47 @@ +public class CountingSort +{ + public static 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