package week5;
import org.junit.Test;
public class Summery {
@Test
public void test(){
int[] A = {7467,1247,3275,6792,9187,9134,4675,1239};
radixsort(A,4,10000);
}
/*
* @para A 需要排序的数组
* @para length A中数组的数的位数
* @para div 10^位数
* */
public int[] radixsort(int[] A,int length,int div){
int[] Aa = A;
//递归调用
if(length > 1){
Aa = radixsort(A,length-1,div/10);
}
int count = Aa.length;
int[] wei = new int[count]; //用来存放A中每个数的位
for(int j=0; j<count;j++){
wei[j] = Aa[j]%div/(div/10);
System.out.print(wei[j]+" ");
}
System.out.println();
for(int m=0;m<count;m++){
int mix = wei[m]; //指定位的最小值
for(int n=m+1; n<count; n++){
if(wei[n]<mix){
mix = wei[n];
int temp = Aa[n];
for(int t=n; t>m; t--){ //将最小值抽取出来,然后数组中的其他数依次后退
Aa[t] = Aa[t-1];
wei[t] = wei[t-1];
}
Aa[m] = temp;
wei[m] = mix;
}
}
for(int x=0;x<count;x++){
System.out.print(Aa[x]+" ");
}
System.out.println("..........................");
}
return Aa; //排序完某位之后的数返回给上一级进行排序 比如排完个位之后,然后返回给十位进行排序
}
}
import org.junit.Test;
public class Summery {
@Test
public void test(){
int[] A = {7467,1247,3275,6792,9187,9134,4675,1239};
radixsort(A,4,10000);
}
/*
* @para A 需要排序的数组
* @para length A中数组的数的位数
* @para div 10^位数
* */
public int[] radixsort(int[] A,int length,int div){
int[] Aa = A;
//递归调用
if(length > 1){
Aa = radixsort(A,length-1,div/10);
}
int count = Aa.length;
int[] wei = new int[count]; //用来存放A中每个数的位
for(int j=0; j<count;j++){
wei[j] = Aa[j]%div/(div/10);
System.out.print(wei[j]+" ");
}
System.out.println();
for(int m=0;m<count;m++){
int mix = wei[m]; //指定位的最小值
for(int n=m+1; n<count; n++){
if(wei[n]<mix){
mix = wei[n];
int temp = Aa[n];
for(int t=n; t>m; t--){ //将最小值抽取出来,然后数组中的其他数依次后退
Aa[t] = Aa[t-1];
wei[t] = wei[t-1];
}
Aa[m] = temp;
wei[m] = mix;
}
}
for(int x=0;x<count;x++){
System.out.print(Aa[x]+" ");
}
System.out.println("..........................");
}
return Aa; //排序完某位之后的数返回给上一级进行排序 比如排完个位之后,然后返回给十位进行排序
}
}