From 35bd2bb9df1788ac8521b3e46fbcc4e3593b2b30 Mon Sep 17 00:00:00 2001 From: Acha Jackson Date: Thu, 5 Oct 2017 13:23:11 +0100 Subject: [PATCH] #96.Added and Implemented Counting sort with Java --- Sorts/CountSort.java | 47 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 Sorts/CountSort.java diff --git a/Sorts/CountSort.java b/Sorts/CountSort.java new file mode 100644 index 000000000000..232df5910588 --- /dev/null +++ b/Sorts/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