-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathredix.cpp
More file actions
46 lines (45 loc) · 849 Bytes
/
Copy pathredix.cpp
File metadata and controls
46 lines (45 loc) · 849 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <iostream>
using namespace std;
int find_max(int A[],int N);
void counting_sort(int A[],int N,int p);
void radix_sort(int A[],int N)
{
int max = find_max(A,N);
int pos;
for(pos=1;max/pos>0;pos*=10)
counting_sort(A,N,pos);
}
void counting_sort(int A[],int N,int pos)
{
int i, B[N];
int C[10]={0};
for(i=0;i<N;i++)
C[(A[i]/pos)%10]++;
for(i=1;i<10;i++)
C[i]=C[i]+C[i-1];
for(i=N-1;i>=0;i--)
B[--C[(A[i]/pos)%10]]=A[i];
for(i=0;i<N;i++)
A[i]=B[i];
}
int find_max(int A[],int N)
{
int i,max=A[0];
for(i=1;i<N;i++)
if(A[i]>max)
max=A[i];
return max;
}
int main()
{
int i,N;
cout<<"Enter the size of Array"<<endl;
cin>>N;
int A[N];
cout<<"Enter the value in Array"<<endl;
for(i=0;i<N;i++)
cin>>A[i];
radix_sort(A,N);
for(i=0;i<N;i++)
cout<<A[i]<<" ";
}