diff --git a/countingSort.cpp b/countingSort.cpp new file mode 100644 index 0000000..6abd1b4 --- /dev/null +++ b/countingSort.cpp @@ -0,0 +1,63 @@ +/* + Contributed by: Mohammad Haziq Khan + GitHub: haaaziq +*/ + +#include +using namespace std; + +// Function to do Counting Sort +void countingSort(int arr[], int n, int digitPlace){ + int sortedData[n]; + int count[10] = {0}; //array for storing count of int from 0-9 in current pass + + for(int i=0; i=0;i--){ + sortedData[--count[arr[i]]] = arr[i]; + } + + cout << "SORTED DATA: "; + for(int i=0; i> size; + + int numbers[size]; + + cout << "Numbers: "; + for(int i=0; i> numbers[i]; + } + cout << "\n"; + + countingSort(numbers, size, 1); +} \ No newline at end of file