Question:

You are given two sorted arrays, A and B, where A has a large enough buffer at the end to hold B.
Write a method to merge B into A in sorted order.

package POJ;

public class Main {

    /**
*
* 11.1 You are given two sorted arrays, A and B, where A has a large enough buffer at the end to hold B.
* Write a method to merge B into A in sorted order.
*
*/
public static void main(String[] args) {
Main so = new Main();
}
public void merge(int[] a, int[] b, int lastA, int lastB){
int indexA=lastA-1;
int indexB=lastB-1;
int indexMerged=lastA+lastB-1;
while(indexA>=0&&indexB>=0){
if(a[indexA]<b[indexB]){
a[indexMerged]=b[indexB];
indexB--;
indexMerged--;
}else{
a[indexMerged]=a[indexA];
indexA--;
indexMerged--;
}
}
while(indexB>=0){
a[indexMerged]=b[indexB];
indexB--;
indexMerged--;
}
}
}

最新文章

  1. Ubuntu14.04下中山大学锐捷上网设置
  2. FCKEditor的用法与下载
  3. Identity-第一章
  4. Managing linux Shell Jobs
  5. The Longest Straight(二分,离散化)
  6. the apple tree
  7. 一 : springmvc常用注解
  8. 【Linux学习笔记】关于ubuntu开机菜单栏和任务栏不见了的有效解决方法
  9. python自动生成bean类
  10. iptables(2)
  11. poj3268 Silver Cow Party(两次dijkstra)
  12. Android典型界面设计(4)——使用ActionBar+Fragment实现tab切换
  13. dubbo项目部署遇到的问题
  14. JS中的兼容问题总结
  15. shell脚本监控cpu/内存使用率 转
  16. Asp.net GridView转换成DataTable
  17. Maven update project...后jdk变成1.5,update project后jdk版本改变
  18. BugPhobia准备篇章:Beta阶段前后端接口文档
  19. 安装sql server 2008重启失败
  20. C/C++ 运算符 &amp; | 运算

热门文章

  1. Python DBUtils
  2. Unique Paths | &amp; ||
  3. js 函数声明方式以及javascript的历史
  4. Android 中的Resource
  5. 转载一篇关于ios静态库的文章
  6. Java for LeetCode 149 Max Points on a Line
  7. Java for LeetCode 029 Divide Two Integers
  8. 2.python基础深入(元组、字符串、列表、字典)
  9. DP:Apple Catching(POJ 2385)
  10. CodeForces - 426B(对称图形)