From 70d42cd072cc5ca27af619fa6bb90cd7c794f334 Mon Sep 17 00:00:00 2001 From: Ashwek Swamy <39827514+ashwek@users.noreply.github.com> Date: Thu, 1 Nov 2018 12:05:30 +0530 Subject: [PATCH] Create Counting_Sort.cpp --- Sorting/Counting_Sort.cpp | 55 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 Sorting/Counting_Sort.cpp diff --git a/Sorting/Counting_Sort.cpp b/Sorting/Counting_Sort.cpp new file mode 100644 index 000000000..bea604a98 --- /dev/null +++ b/Sorting/Counting_Sort.cpp @@ -0,0 +1,55 @@ +#include +using namespace std; + +int Max(int Arr[], int N){ + int max = Arr[0]; + for(int i=1; i max) + max = Arr[i]; + return max; +} + +int Min(int Arr[], int N){ + int min = Arr[0]; + for(int i=1; i=0; i--){ + Sorted_Arr[Count[Arr[i]-min]-1] = Arr[i]; + Count[Arr[i]-min]--; + } + + return Sorted_Arr; +} + +int main(){ + + int Arr[] = {47, 65, 20, 66, 25, 53, 64, 69, 72, 22, 74, 25, 53, 15, 42, 36, 4, 69, 86, 19}, N = 20; + int *Sorted_Arr; + + cout<<"\n\tOrignal Array = ";Print(Arr, N); + Sorted_Arr = Counting_Sort(Arr, N); + cout<<"\n\t Sorted Array = ";Print(Sorted_Arr, N); + cout<