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++;
10. 基数排序按个、十、百位依次归类排序;
public void radixSort(int[
nums){ int min = Integer.MAX_VALUE; int max = Integer.MIN_VALUE; for (int num : nums) {
min = Math.min(min num);
max = Math.max(max num);
for (int i = 0; i < nums.length; i++) {
nums[i
-= min;
max -= min; int maxLen = (max+\"\").length(); int[
[
bucket = new int[nums.length
[10
; int[
bucketCount = new int[10
; for (int i = 0 n = 1; i < maxLen; i++ n*=10) { for (int num : nums) { int digitVal = num / n % 10;
bucket[bucketCount[digitVal
[digitVal
= num;
bucketCount[digitVal
++;
int index = 0; for (int j = 0; j < bucketCount.length; j++) { if(bucketCount[j
> 0){ for (int k = 0; k < bucketCount[j
; k++) {
nums[index
= bucket[k
[j
;
index++;
bucketCount[j
= 0;
for (int i = 0; i < nums.length; i++) {
nums[i
+= min;
11. 使用集合或 API11.1 优先队列public void priorityQueueSort(int[
nums){
PriorityQueue<Integer> queue = new PriorityQueue<>(); for(int num : nums){ queue.offer(num);
for (int i = 0; i < nums.length; i++) {
nums[i
= queue.poll();
11.2 Java APIpublic void arraysApiSort(int[
nums){
Arrays.sort(nums);
- 社交|腾讯视频为IP编写「价值算法」
- 新书推荐 │ 大数据算法设计与分析
- 算法|75英寸最值得入手的大屏电视,性能画质没得挑
- 算法|“赞奇科技”获得数千万元战略投资
- 中国移动|中国移动新一代超级SIM卡芯片来了:2MB存储、算法翻3倍
- 算法|为什么你只是说了某样东西,手机就会给你推送相关商品?几步教你轻松解决!
- 为了抢用户,Facebook要改算法了
- 算法|侃侃而谈| 为什么视频网站必然走向兼并整合?
- boss直聘|腾讯视频网络电影:创新赛道,多点齐发,全面布局2022
- 算法|魅族19官方预热:部分配置曝光,首批渲染图出炉!
