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);
- 腾讯|国家出手,人民日报正式发声,“算法时代”即将落幕?
- BOSS直聘全年利润由负转正,营收42.6亿元超市场预期
- 工程师|官方揭秘小米12万物追焦功能:灵感来自算法工程师2岁儿子
- 算法|算法新规将施行 超半数受访者表示会选择关闭算法推荐
- 算法|如果你这么去理解HashMap就会发现它真的很简单
- 华为|算法 | Java 常见排序算法(纯代码)
- 借力算法,海天瑞声驾驭自动驾驶“新引擎”
- 创投|人民日报:莫让算法变“算计”,也该听听曹德旺的忠告了!
- 算法|国家出手,人民日报正式发声,“算法时代”即将落幕?
- 算法|银行网贷平台为啥拒绝披露委外的催收信息,这就是原因