From 19517fbcf598cf255ba35a40533a8bd54c939122 Mon Sep 17 00:00:00 2001 From: Acha Jackson Date: Sun, 1 Oct 2017 13:21:25 +0100 Subject: [PATCH] #20. Added and implemented counting sort with java. --- Sorting Algorithms/Countsort.java | 47 +++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 Sorting Algorithms/Countsort.java 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