MCPcopy Create free account
hub / github.com/codemistic/Data-Structures-and-Algorithms / counting_sort

Function counting_sort

CPP/sorting/countingsort.cpp:11–29  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9
10using namespace std;
11void counting_sort(int arr[],int n){
12 int large=INT_MIN;
13 for(int i=0;i<n;i++)
14 large=max(large+1,arr[i]);
15
16 vector<int> v(n,0);
17 for(int i=0;i<n;i++){
18 v[arr[i]]++;
19 }
20 int z=0;
21 for(int i=0;i<n;i++){
22 while(v[i]>0){
23 arr[z]=i;
24 v[i]--;
25 z++;
26 }
27 }
28
29}
30void printarray1(int arr[],int n){
31 for(int i=0;i<n;i++){
32 cout<<arr[i]<<", ";

Callers 1

mainFunction · 0.85

Calls 1

maxFunction · 0.50

Tested by

no test coverage detected