-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathradix.java
More file actions
49 lines (46 loc) · 1.75 KB
/
radix.java
File metadata and controls
49 lines (46 loc) · 1.75 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
/**
* Write a description of class radix here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class radix
{
public static void main (String args[]){
int arrayforsort[] = {25,589,255,62,1,90,431,827,777,240,5};
int finalarray[];
boolean check = false;
int pass = 0;
for(int i=0; i <arrayforsort.length; i++){
System.out.print(arrayforsort[i] + " ");
}
System.out.print("\n");
for (int j=10; j<10000; j = j*10){
pass++;
System.out.print("sort pass"+pass+"\n");
for(int i=0; i <arrayforsort.length-1; i++){
if ((arrayforsort[i]%j)-(arrayforsort[i]%(j/10))>((arrayforsort[i+1]%j)-(arrayforsort[i+1]%(j/10)))){
//System.out.println((arrayforsort[i]%j)+" "+(arrayforsort[i]%(j/10)));
int temp = arrayforsort[i+1];
arrayforsort[i+1]=arrayforsort[i];
arrayforsort[i]=temp;
i=0;
}
if ((arrayforsort[i]%j)-(arrayforsort[i]%(j/10))>((arrayforsort[i+1]%j)-(arrayforsort[i+1]%(j/10)))){
int temp = arrayforsort[i+1];
arrayforsort[i+1]=arrayforsort[i];
arrayforsort[i]=temp;
}
}
for(int i=0; i <arrayforsort.length; i++){
System.out.print(arrayforsort[i] + " ");
}
System.out.print("\n");
check = true;
}
System.out.print("\nfinal sorted order\n");
for(int i=0; i <arrayforsort.length; i++){
System.out.print(arrayforsort[i] + " ");
}
}
}