-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMergeSort.java
More file actions
30 lines (28 loc) · 751 Bytes
/
MergeSort.java
File metadata and controls
30 lines (28 loc) · 751 Bytes
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
package basic;
public class MergeSort {
public static int[] merge_sort(int[] num1, int[] num2) {
int num1len = num1.length;
int num2len = num2.length;
int i = 0, j = 0, k = 0;
int[] c = new int[10];
while (i < num1len && j < num2len) {
if (num1[i] <= num2[j] && i < num1len) {
c[k++] = num1[i++];
}
if (num1[i] >= num2[j]) {
c[k++] = num2[j++];
}
}
if (i < num1len) {
while (i < num1len) {
c[k++] = num1[i++];
}
}
if (j < num2len) {
while (j < num2len) {
c[k++] = num2[j++];
}
}
return c;
}
}