基数排序算法
来源:互联网 发布:苹果手机远程抹除数据 编辑:程序博客网 时间:2024/05/13 11:53
package week5;
import org.junit.Test;
public class RadixSort2 {
//测试函数
@Test
public void test(){
int[] A = {7467,1247,3275,6792,9187,9134,4675,1239};
radixsort(A,4);
}
/*基数排序
* @para A要排序的数
* @para A中数的长度
* */
public void radixsort(int[] A,int length){
int count = A.length;
int[] wei = new int[count]; //用来存放A中每个数的位
int div = 10;
for(int i=0; i<length; i++){
for(int j=0; j<count; j++){//获取每个数的个.十.百.千位
wei[j] = A[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 = A[n];
for(int t=n; t>m; t--){ //将最小值抽取出来,然后数组中的其他数依次后退
A[t] = A[t-1];
wei[t] = wei[t-1];
}
A[m] = temp;
wei[m] = mix;
}
}
for(int x=0;x<count;x++){
System.out.print(A[x]+" ");
}
System.out.println("..........................");
}
div *= 10;
}
}
}
import org.junit.Test;
public class RadixSort2 {
//测试函数
@Test
public void test(){
int[] A = {7467,1247,3275,6792,9187,9134,4675,1239};
radixsort(A,4);
}
/*基数排序
* @para A要排序的数
* @para A中数的长度
* */
public void radixsort(int[] A,int length){
int count = A.length;
int[] wei = new int[count]; //用来存放A中每个数的位
int div = 10;
for(int i=0; i<length; i++){
for(int j=0; j<count; j++){//获取每个数的个.十.百.千位
wei[j] = A[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 = A[n];
for(int t=n; t>m; t--){ //将最小值抽取出来,然后数组中的其他数依次后退
A[t] = A[t-1];
wei[t] = wei[t-1];
}
A[m] = temp;
wei[m] = mix;
}
}
for(int x=0;x<count;x++){
System.out.print(A[x]+" ");
}
System.out.println("..........................");
}
div *= 10;
}
}
}
0 0
- 基数排序算法
- 算法-----基数排序
- 基数排序算法
- 基数排序算法
- 基数排序算法
- 基数排序算法
- 算法--基数排序
- 基数排序算法
- [算法] 基数排序
- 基数排序算法
- 基数排序算法
- 算法---基数排序
- 基数排序算法
- 基数排序算法
- 【算法】基数排序
- 基数排序算法
- 基数排序算法
- 基数排序算法
- 关于内存地址分配之几个注意事项
- 解决java.lang.NullPointerException: View must not be null!
- [BZOJ]1027 合金
- hdoj-1040-As Easy As A+B(解题报告)
- Part07
- 基数排序算法
- 7种结构型模式之:享元模式(Flyweight)与数据库连接池的原理
- java中线程的理解
- [BZOJ]1030 文本生成器
- Part08
- struts2中Action名称的搜索顺序
- RTMP 协议
- 对象的生命周期
- 面向对象编程理论