Commonly asked Data Structures and Algorithms Problems by big tech and different solution approaches with code in Java and C

Powered by Blogger.

Sunday, January 22, 2017

Counting Sort 1



this sorting is done by hash function.
it is a better approach which take less time , approx O(N).


#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;


int main() {
  int n;
    cin>>n;
    int arr[100]={0},inp[n];
    for(int i=0;i<n;i++)
        {
        cin>>inp[i];
        arr[inp[i]]++;
    }
    for(int i=0;i<100;i++)
        cout<<arr[i]<<" ";
    return 0;
}

0 Comments:

Post a Comment

Stats