Answer-
Your code given below here as your
requirement-
- #include<iostream>
- using namespace std;
- int z=0;
- void CouSort(int A[],int B[],int t) //using function for the
counting sort
- {
- int C[z];
- for(int i=0;i<z+1;i++)
- {
- C[i]=0;
- }
- for(int j=1;j<=t;j++)
- {
- //increment it at position x in C*/
- C[A[j]]++;
- }
- for(int i=1;i<=z;i++)
- {
- C[i]+=C[i-1];
- }
- for(int j=t;j>=1;j--)
- {
- B[C[A[j]]]=A[j];
- C[A[j]]=C[A[j]]-1;
- }
- }
- int main()
- {
- int t;
- cout<<"please enter array size and after
enter array element :";
- cin>>t;
-
- int A[t],B[t];
-
- for(int i=1;i<=t;i++)
- {
- cin>>A[i];
- if(A[i]>z)
- {
- z=A[i];
- }
- }
- CouSort(A,B,t); // driver code for function
- for(int i=1;i<=t;i++)
- {
- cout<<B[i]<<" ";
////print the sorted sequence on the
- }
- cout<<endl;
- return 0;
- }
screenshot of output and running program -
Note- Please do upvote, if any problem then comment in
box sure I will help.