diff --git a/9.CountingSort.cpp b/9.CountingSort.cpp new file mode 100644 index 0000000..8492baf --- /dev/null +++ b/9.CountingSort.cpp @@ -0,0 +1,50 @@ +/* + * This program takes an array from the user + * sorts it using counting sort + * Prints the sorted array + * For more information about Counting Sort Algorithm: https://en.wikipedia.org/wiki/Counting_sort + * + * Coded by: Abdurrezak EFE + * + * */ +#include +#include +using namespace std; + +void counting_sort(int arr[], int k, int maxx) +{ + int counts[maxx+1]; + for(int i=0;i> k; + + int arr[k]; + int maxx = -1; + for(int i=0;i> arr[i], maxx = max(maxx,arr[i]); + + counting_sort(arr, k, maxx); //sorting + + for(int i=0;i