public void heapSort2(int[] nums) {
for(int i = nums.length/2-1; i >= 0; i--){
sift(nums, i, nums.length);
}
for (int i = nums.length-1; i > 0; i--) {
int temp = nums[0];
nums[0] = nums[i];
nums[i] = temp;
sift(nums, 0, i);
}
}
private void sift(int[] nums, int parent, int len) {
int value = nums[parent];
for (int child = 2*parent +1; child < len; child = child*2 +1) {
if(child+1 < len && nums[child+1] > nums[child]){
child++;
}
if(nums[child] > value){
nums[parent] = nums[child];
parent = child;
} else {
break;
}
}
nums[parent] = value;
}
PS:大顶堆实现升序,每次将最大值移到堆的最后一个位置上
上面是“java常见排序算法——堆排序(附代码示列)”的全面内容,想了解更多关于 后端开发 内容,请继续关注web建站教程。
当前网址:https://ipkd.cn/webs_4260.html
workflows工作流
一个港口配备了小型船只、起重机、集装箱和码头
树上挂着一只表情可爱的香蕉ComfyUI工作流二
一个黄色的海绵宝宝ComfyUI工作流
森林里有一个皮肤像抛光黑曜石的生物
一座千年九尾白狐玉雕ComfyUI工作流
一个骷髅海盗船长ComfyUI工作流
一只透明老虎骨骼标本ComfyUI工作流
一颗巨型的木星ComfyUI工作流
猜你喜欢
声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

制作一个好玩的倒计时
一起去看流星雨(代码)
canvas经线动画走到效果
利用js+css3做一个小鱼游泳特效
css3搭积木叠加图形
css3+js菜单点击动态效果
canvas黑洞漩涡(canvas+js)
HTML5 Canvas 刻度尺










