Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
CountingSort
//g++ 7.4.0 //counting sort code credit to simplesnippets.tech // # include <iostream> using namespace std; void countSort(int [],int,int); void countSort(int input[],int s, int r) { int output[s]; int count[r]; for(int i=0;i<r;i++) count[i]=0; for(int i=0;i<s;i++) ++count[input[i]]; for(int i=1;i<r;i++) count[i]=count[i]+count[i-1]; for(int i=0;i<s;i++) output[--count[input[i]]] = input[i]; for(int i=0;i<s;i++) input[i]=output[i]; } int main() { int sz=10; int range = 10; int a[sz]; cout<<"Enter "<<sz<<" integers in any order in range of 0-9: "<<endl; for(int i=0;i<sz;i++) { cin>>a[i]; } cout <<endl; cout<<"Before Sorting"<<endl; for(int i=0;i<sz;i++) { cout<<a[i]<<" "; } cout<<endl; countSort(a,sz,range); cout<<"After Sorting"<<endl; for(int i=0;i<sz;i++) { cout<<a[i]<<" "; } cout<<endl; return 0; }
run
|
edit
|
history
|
help
0
variadic template
Value equal to index value
diamond
VirtualResto
Bank System
543
same
runtime template mode processor
Tejas choudhari
Mr