public void bucketSort(int[] nums){
int max = Integer.MIN_VALUE;
int min = Integer.MAX_VALUE;
for(int num : nums){
max = Math.max(max, num);
min = Math.min(min, num);
}
int bucketCount = (max-min)/nums.length+1;
List<List<Integer>> bucketList = new ArrayList<>();
for (int i = 0; i < bucketCount; i++) {
bucketList.add(new ArrayList<>());
}
for(int num : nums){
int index = (num-min)/nums.length;
bucketList.get(index).add(num);
}
for(List<Integer> bucket : bucketList){
Collections.sort(bucket);
}
int j = 0;
for(List<Integer> bucket : bucketList){
for(int num : bucket){
nums[j] = num;
j++;
}
}
}
PS:类似计数排序,不同点在于统计的是某个区间(桶)里的数。
上面是“java常见排序算法——桶排序(附代码示列)”的全面内容,想了解更多关于 后端开发 内容,请继续关注web建站教程。
当前网址:https://ipkd.cn/webs_4262.html
workflows工作流
一个精心制作的微型赛车场ComfyUI工作流
文生图工作流:树枝上站着一只鸟
一只巨大的古代乌龟后面建有一座城市的超现实场景
树上一个快乐的猕猴桃ComfyUI工作流
stvmccrr风格的玫瑰花ComfyUI工作流
一只黑色的小猫在童话森林里嗅着一朵发光的外星花
一个20岁丰满的女孩ComfyUI工作流
一颗翡翠玉雕盆栽树comfyui工作流
猜你喜欢
声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

css3搭积木叠加图形
3d空间行走效果
如何利用css3+js做一个下雨效果
纯css制作卡通头像(随鼠标转头)
纯css3绘制的小鸟
利用html5+css3实现滚雪球效果(附代码)
css3做一个风雨雷电天气动态图标






