-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOrderArraySort.java
More file actions
44 lines (42 loc) · 976 Bytes
/
Copy pathOrderArraySort.java
File metadata and controls
44 lines (42 loc) · 976 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
package com.wg.offerAlgorithm;
/*
* 将两个有序数组合并为一个升序数组
*/
public class OrderArraySort {
public int[] getArraySort(int[]m,int[] n){
int im=0;
int jn=0;
int[] mn =new int[m.length+n.length];
while(im<m.length && jn<n.length){
if(m[im]<=n[jn]){
mn[im+jn]=m[im];
im++;
}else{
mn[im+jn]=n[jn];
jn++;
}
}
while(im < m.length){
mn[im + jn] = m[im];
im++;
}
while(jn < n.length){
mn[im + jn] = n[jn];
jn++;
}
return mn;
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int[] m = {1,3,5,7,9,11,12,13};
int[] n = {2,3,6,8,10};
OrderArraySort oas = new OrderArraySort();
int[] mn = oas.getArraySort(m, n);
for(int i=0;i<mn.length;i++){
System.out.print(mn[i]+" ");
}
}
}