Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Name: Abu Hurayra
- Handle: HurayraIIT
- Institute: IIT_JU
- Date: 20/3/2019 */
- #include <bits/stdc++.h>
- using namespace std;
- typedef long long LL;
- typedef string S;
- typedef double D;
- typedef vector<int> vi;
- typedef stack<int> si;
- typedef queue<int> qi;
- typedef priority_queue<int> pqi;
- typedef pair<int,int> pi;
- #define pi acos(-1.0)
- #define PSB push_back
- #define PPB pop_back
- #define REP(i,a,b) for(i=a;i<=b;i++)
- void CountSort(int a[] , int n , int max);
- void PrintSortedArray(int a[] , int n);
- int main()
- {
- #ifndef ONLINE_JUDGE
- freopen("input.txt","r",stdin);
- freopen("output.txt","w",stdout);
- #endif
- int n, i, j, max = -1;
- cin >> n;
- int a[n];
- for(i = 0 ; i < n ; i++)
- {
- cin >> a[i];
- if(a[i] > max) max = a[i];
- }
- CountSort(a , n , max);
- PrintSortedArray(a , n);
- return 0;
- }
- void CountSort(int a[] , int n , int max)
- {
- int count[max+10] = {0} , i , j = 0 , k = 0 ;
- for(i = 0 ; i < n ; i++)
- {
- count[a[i]]++;
- }
- for(i = 0 ; i <= max+5 ; i++)
- {
- while(count[i]--)
- {
- a[j++] = i ;
- }
- }
- return;
- }
- void PrintSortedArray(int a[] , int n)
- {
- for(int i = 0 ; i < n ; i++) cout << a[i] << " ";
- cout << endl;
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement