-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRadixSort.txt
More file actions
83 lines (63 loc) · 1.38 KB
/
RadixSort.txt
File metadata and controls
83 lines (63 loc) · 1.38 KB
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
public class radixsort {
public static void main(String args[]){
int a[] = {355,720,437,657,839,282,421,432,134,141,123,234};
int lsd[] = new int[a.length];
int mid[] = new int[a.length];
int msd[] = new int[a.length];
for(int i=0;i<a.length;i++){
int splitup = a[i];
lsd[i] = splitup%10;
int temp = splitup/10;
mid[i] = temp % 10;
msd[i] = temp / 10;
}
for(int i=0;i<lsd.length;i++){
for(int j=0;j<i;j++){
if(lsd[i] < lsd[j]){
int swap = lsd[j];
int mswap = mid[j];
int upswap = msd[j];
lsd[j] = lsd[i];
mid[j] = mid[i];
msd[j] = msd[i];
lsd[i] = swap;
mid[i] = mswap;
msd[i] = upswap;
}
}
}
for(int i=0;i<mid.length;i++){
for(int j=0;j<i;j++){
if(mid[i] < mid[j]){
int swap = lsd[j];
int mswap = mid[j];
int upswap = msd[j];
lsd[j] = lsd[i];
mid[j] = mid[i];
msd[j] = msd[i];
lsd[i] = swap;
mid[i] = mswap;
msd[i] = upswap;
}
}
}
for(int i=0;i<msd.length;i++){
for(int j=0;j<i;j++){
if(msd[i] < msd[j]){
int swap = lsd[j];
int mswap = mid[j];
int upswap = msd[j];
lsd[j] = lsd[i];
mid[j] = mid[i];
msd[j] = msd[i];
lsd[i] = swap;
mid[i] = mswap;
msd[i] = upswap;
}
}
}
for(int i=0;i<lsd.length;i++){
System.out.println("The Sorted array is " + msd[i] + mid[i] + lsd[i]);
}
}
}