Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- int main()
- {
- int input[100],output[100],temp[100],n,k;
- cout<<"Length of input array: ";
- cin>>n;
- for(int i=1; i<=n; i++)
- {
- cin>>input[i];
- }
- k=input[1];
- for(int i=2; i<=n; i++)
- {
- if(k<input[i])
- {
- k=input[i];
- }
- }
- cout<<"Largest Number is"<<k<<endl;
- for(int i=1; i<=k; i++)
- {
- temp[i]=0;
- }
- cout<<"Declare temp array zero.."<<endl;
- for(int i=1; i<=k; i++)
- {
- cout<<temp[i]<<endl;
- }
- for(int j=1; j<=n; j++)
- {
- temp[input[j]]+=1;
- }
- cout<<"Temp array.."<<endl;
- for(int i=1; i<=k; i++)
- {
- cout<<temp[i]<<endl;
- }
- for(int i=2; i<=k; i++)
- {
- temp[i]=temp[i]+temp[i-1];
- }
- cout<<"Increment of temp array.."<<endl;
- for(int i=1; i<=k; i++)
- {
- cout<<temp[i]<<endl;
- }
- cout<<"Counting sort"<<endl;
- for(int j=n; j>=1; j--)
- {
- output[temp[input[j]]]=input[j];
- temp[input[j]]-=1;
- }
- for(int i=1;i<=n;i++){
- cout<<output[i]<<endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement