Can we skip the step of making each c[i]=c[i]+c[i-1] and directly print all the elements from the c[i] originally produced ??like i did it below and it works fine.I have doubt in the complexity of creating output array b.plzz help
using namespace std;
int main()
{
int a[15],c[10],b[10],R,N;
cout<<“Range=”;cin>>R; //Assuming range form 0 to R
cout<<"\no of elements";cin>>N;
int i=0;
while(i!=N)
{
cin>>a[i];
i++;
}
for(i=0;i<=R;i++){c[i]=0;} // complexity O®
for(i=0;i<N;i++) //complexity O(N)
{
c[a[i]]++;
}
int k=0;
for(i=0;i<=R;i++)
{
while(c[i]!=0)
{
b[k]=i;
c[i]–;
k++;
}
}
//to print the array;
for(i=0;i<N;i++)
{
cout<<b[i]<<" ";
}
return 0;
}