
//归
public void mergeSortDfs(int[] nums, int l, int r){
if(l >= r){
return;
}
int m = (l+r)/2;
mergeSortDfs(nums, l, m);
mergeSortDfs(nums, m+1, r);
merge(nums, l, m, r);
}
//并
private void merge(int[] nums, int left, int mid, int right){
int[] temp = new int[right-left+1];
int l = left;
int m = mid+1;
int i = 0;
while(l <= mid && m <= right){
if(nums[l] < nums[m]){
temp[i++] = nums[l++];
} else {
temp[i++] = nums[m++];
}
}
while(l <= mid){
temp[i++] = nums[l++];
}
while(m <= right){
temp[i++] = nums[m++];
}
System.arraycopy(temp, 0, nums, left, temp.length);
}
上面是“java常见排序算法——归并排序(附代码示列)”的全面内容,想了解更多关于 后端开发 内容,请继续关注web建站教程。
当前网址:https://m.ipkd.cn/webs_4258.html
声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

javascript如何判断是否存在
VideoTutor:根据用户提出的问题生成动画、语音引导的AI教育辅助工具