-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMergeSort.java
More file actions
46 lines (33 loc) · 909 Bytes
/
MergeSort.java
File metadata and controls
46 lines (33 loc) · 909 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package com.chen.test;
/**
* @author : chen weijie
* @Date: 2020-04-22 07:43
*/
public class MergeSort {
public void solution(int[] a, int[] b) {
int[] result = new int[a.length + b.length];
int i = 0, j = 0, l = 0;
while (i < a.length && j < b.length) {
if (a[i] < b[j]) {
result[l++] = a[i++];
} else {
result[l++] = b[j++];
}
}
while (j < b.length) {
result[l++] = b[j++];
}
while (i < a.length) {
result[l++] = a[i++];
}
}
public boolean checkSort(int[] array) {
boolean change = true;
for (int i = 0; i < array.length && change; i++) {
for (int j = 0; j < array.length - 1 - i; j++) {
change = array[j] <= array[j + 1];
}
}
return change;
}
}