Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
34 lines (30 loc) · 887 Bytes

File metadata and controls

34 lines (30 loc) · 887 Bytes
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package sort;
/**
* 归并排序的思想是将数组分成两部分,分别进行排序,然后归并起来。
*
* @author 刘壮飞
* https://github.com/zfman.
* https://blog.csdn.net/lzhuangfei.
*/
public abstract class MergeSort<T extends Comparable<T>> extends Sort<T> {
protected T[] tmp;
protected void merge(T[] nums, int l, int m, int h) {
//i:待归并的前者的位置,j:待归并的后者的位置
int i = l, j = m + 1;
for (int k = l; k <= h; k++) {
tmp[k] = nums[k];
}
//两个子序列合并
int v=l;
while(i<=m&&j<=h){
if(tmp[i].compareTo(tmp[j])<=0) nums[v++]=tmp[i++];
else nums[v++]=tmp[j++];
}
if(m>i){
for(;j<=h;j++) nums[v++]=tmp[j];
}
if(j>h){
for(;i<=m;i++) nums[v++]=tmp[i];
}
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.