-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patha.cpp
85 lines (46 loc) · 1.06 KB
/
a.cpp
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include <stdio.h>
void RadixSort(int array[], int size){
int d=-9,temp, d_temp;
for(int i=0; i<size; i++){
temp = array[i];
d_temp=0;
while(temp>0){
temp=temp/10;
d_temp++;
}
if(d<=d_temp){
d=d_temp;
}
}
int bs = 1;
for(int i=0; i<d; i+=1){
int output[size];
int j, count[10] = { 0 };
for (j = 0; j < size; j++){
count[(array[j] / bs) % 10]++;
}
for (j = 1; j < 10; j++){
count[j] += count[j - 1];
}
for (j = size - 1; j >= 0; j--) {
output[count[(array[j] / bs) % 10] - 1] = array[j];
count[(array[j] / bs) % 10]--;
}
for (j = 0; j < size; j++){
array[j] = output[j];
}
bs*=10;
}
}
void PrintArray(int array[], int size){
for(int i=0; i<size; i++){
printf("%d ", array[i]);
}
}
int main(){
int array[] = {10,2,3,5,5,40,10,89,9,7,7,0,9,5987542,26,3,1,3,6,55,8,8,7,945,5586,0,0};
int size = sizeof(array)/sizeof(array[0]);
RadixSort(array, size);
PrintArray(array, size);
return 0;
}