public class MergeSort {
static void show(int a[]) {
int i;
for (i = 0; i < a.length; i++) {
System.out.print(a[i]+"-");
}
System.out.println("\n");
}
static void merge(int arr1[], int arr2[], int res[]) {
int i=0,j=0;
int idx = 0;
for (;;) {
System.out.print("show res:");
show(res);
if(i>=10 || j>=10)break;
if (arr1[i] <= arr2[j]) {
res[idx] = arr1[i];
i++;
} else {
res[idx] = arr2[j];
j++;
}
idx++;
}
if(i<10){
for(;i<10;i++){
res[idx] = arr1[i];
idx++;
}
}
if(j<10){
for(;j<10;j++){
res[idx] = arr1[j];
idx++;
}
}
return;
}
public static void main(String args[]) {
int arr1[] = { 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
int arr2[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
show(arr1);
show(arr2);
int res[] = new int[20];
show(res);
merge(arr1, arr2, res);
System.out.print("final:");show(res);
}
}

【JAVA】merge two array by order的更多相关文章

  1. 【leetcode】Merge Sorted Array

    题目描述 Given two sorted integer arrays A and B, merge B into A as one sorted array. Note: You may assu ...

  2. 【题解】【数组】【Leetcode】Merge Sorted Array

    Given two sorted integer arrays A and B, merge B into A as one sorted array. Note: You may assume th ...

  3. 【leetcode】Merge Sorted Array(合并两个有序数组到其中一个数组中)

    题目: Given two sorted integer arrays A and B, merge B into A as one sorted array. Note: You may assum ...

  4. 【LeeCode88】Merge Sorted Array★

    1.题目描述: 2.解题思路: 题意:两个由整数构成的有序数组nums1和nums2,合并nums2到nums1,使之成为一个有序数组.注意,假设数组nums1有足够的空间存储nums1和nums2的 ...

  5. 【Leetcode】【Easy】Merge Sorted Array

    Given two sorted integer arrays A and B, merge B into A as one sorted array. Note:You may assume tha ...

  6. 【Java】 List和Array转换

    List转Array toArray 首先展示初学者容易犯的错误示例 List<String> strList = new ArrayList<>(); strList.add ...

  7. 【LeetCode】Merge Sorted Array(合并两个有序数组)

    这道题是LeetCode里的第88道题. 题目描述: 给定两个有序整数数组 nums1 和 nums2,将 nums2 合并到 nums1 中,使得 num1 成为一个有序数组. 说明: 初始化 nu ...

  8. 【Java】HashMap源码分析——常用方法详解

    上一篇介绍了HashMap的基本概念,这一篇着重介绍HasHMap中的一些常用方法:put()get()**resize()** 首先介绍resize()这个方法,在我看来这是HashMap中一个非常 ...

  9. 【Java】-NO.16.EBook.4.Java.1.012-【疯狂Java讲义第3版 李刚】- JDBC

    1.0.0 Summary Tittle:[Java]-NO.16.EBook.4.Java.1.012-[疯狂Java讲义第3版 李刚]-  JDBC Style:EBook Series:Java ...

随机推荐

  1. 87. [NOIP2000] 乘积最大

    ★☆   输入文件:cjzd.in   输出文件:cjzd.out   简单对比 时间限制:1 s   内存限制:128 MB 问题描述 今年是国际数学联盟确定的“2000——世界数学年”,又恰逢我国 ...

  2. jquery插件集合

    jQuery由美国人John Resig创建,至今已吸引了来自世界各地的众多javascript高手加入其team. jQuery是继prototype之后又一个优秀的Javascrīpt框架.其经典 ...

  3. linux nohup & 简单使用

    线上通常nohup配合&启动程序,同时免疫SIGINT和SIGHUP信号,从而保证程序在后台稳定运行 & 1.后台运行,输出默认到屏幕 2.免疫SIGINT信号,比如Ctrl+c不会杀 ...

  4. 安卓app测试之Monkey日志分析

    转:原文:https://blog.csdn.net/a136332462/article/details/76066909  一.一般测试结果分析-搜索关键字: 1.无响应问题可以在日志中搜索 “A ...

  5. jQuery鼠标划入划出

    今天来简单的谈谈jQuery的一个划入划出的方法,.首先划入划出能想到的东西有哪些呢,. 1:hover 2:mouseenter/mouseleave 3:mouseover/mouseout. 一 ...

  6. telnet mysql3306端口失败

    在linux上telnet远程mysql端口失败,经过上网查找后,找到多种方法. (1)我在本地的Navicat上新增了一个用户,主机名是linux的ip,也可以是 %(百分号代表这个用户可以在任何地 ...

  7. cc.Node—场景树

    对于cc.Node我分了四个模块学习: 1.场景树,2.事件响应,3.坐标系统,4.Action的使用:在此记录经验分享给大家. 场景树 1: creator是由一个一个的游戏场景组成,通过代码逻辑来 ...

  8. Luogu P1991 无线通讯网

    P1991 无线通讯网 题目描述 国防部计划用无线网络连接若干个边防哨所.2 种不同的通讯技术用来搭建无线网络: 每个边防哨所都要配备无线电收发器:有一些哨所还可以增配卫星电话. 任意两个配备了一条卫 ...

  9. Cash Machine POJ - 1276

    解法 多重背包板子题 多重背包板子 如果上限的体积大于了给定的体积那么套完全背包 否则二进制优化成01背包 代码 #include <iostream> #include <cstr ...

  10. ubuntu环境搭建DNS服务器

    1 安装bind9 apt install bind9 2 修改 named.conf.local,添加要解析的域名及对应的域名配置文件 zone "test.cn"{ type ...