/**
* 基数排序
*/
public class RadixSort {
private static int getMax(int[] a ){
int max = a[0];
for (int i : a){
if (i > max){
max = i;
}
}
return max;
}
private static void countSort(int[] a, int exp){
int[] output = new int[a.length];
int[] buckets = new int[10];
for (int anA : a) {
buckets[(anA / exp) % 10]++;
}
for (int i : buckets)
System.out.print(i + " ");
System.out.println();
for (int i = 1; i < 10; i++){
buckets[i] += buckets[i - 1];
}
for (int i : buckets)
System.out.print(i + " ");
System.out.println();
for (int i = a.length - 1; i >= 0; i--){
output[buckets[(a[i] / exp) % 10] - 1] = a[i];
buckets[(a[i] / exp) % 10]--;
}
for (int i = 0; i < a.length; i++){
a[i] = output[i];
}
output = null;
buckets = null;
}
private static void radixSort(int[] a){
int max = getMax(a);
for (int exp = 1; max / exp > 0; exp *= 10){
countSort(a, exp);
}
}
public static void main(String[] args){
int[] a = {53, 3, 542, 748, 14, 214, 154, 63, 616};
radixSort(a);
for (int i : a){
System.out.print(i + " ");
}
}
}
排序算法的Java实现
需积分: 5 173 浏览量
2023-07-19
15:58:15
上传
评论
收藏 4KB ZIP 举报
我的样子平淡的出奇
- 粉丝: 0
- 资源: 5
最新资源
- 笔记实验六,spark,大数据分析
- ####蓝桥杯python的详细的信息介绍
- 电子万年历软件仿真(经过多次修改,保证正确性)
- Unity XR 手势射击控制脚本(适用于任何可手势识别的设备)
- 机械设计全自动电表(NB和IC卡表)控制和上壳装配线sw16可编辑非常好的设计图纸100%好用.zip
- 基于matlab的EAN-13条形码识别系统GUI界面.zip代码53
- matlab基于bp神经网络交通信号标志识别GUI界面13个标志.zip代码54
- 电子万年历答辩实物展示视频mp4格式
- 基于python实现的程序,包括哈希感知算法cvHash,图像切割cvsplit,固定目标检测cvRec(附文档ppt)等
- 计算0-10000之间所有偶数的和
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈