java数据结构代码记录---归并排序代码

来源:互联网 发布:办公室office软件下载 编辑:程序博客网 时间:2024/05/29 19:00
public static int[] merge() {int[] a = { 1, 3, 56, 78, 98, 322, 9234 };int[] b = new int[] { 10, 40, 56, 78, 100 };int l = a.length;int ml = b.length;int[] c = new int[a.length + b.length];int m = 0;int i = 0;// 以a为基准while (m < ml && i < l) {if (a[i] <= b[m]) {c[i + m] = a[i];i++;} else {c[i + m] = b[m];m++;}}// 如果b还有剩余,那么全部加载到cwhile (m < ml) {c[i + m] = b[m];m++;}while (i < l) {c[i + m] = a[i];i++;}return c;}


 

0 0
原创粉丝点击