java语言程序设计第十版(Introduce to java 10th) 课后习题 chapter7-31
来源:互联网 发布:windows app文件夹 编辑:程序博客网 时间:2024/06/04 18:48
package chapter7;import java.util.Arrays;public class T31 {public static void main(String[] args) {int[] list1 = { 1, 3, 4, 5, 16, 61, 111, 121 };int[] list2 = { 2, 4, 5, 6, 7, 8, 9 };int[] newList = merge(list1, list2);System.out.println(Arrays.toString(newList));}public static int[] merge(int[] list1, int[] list2) {int first = 0;// 第一个数组游标int second = 0;// 第二个数组游标int i = 0;// list的游标int[] list = new int[list1.length + list2.length];while ((first != list1.length) && (second != list2.length)) {if (list1[first] < list2[second]) {list[i] = list1[first];first++;i++;} else {list[i] = list2[second];second++;i++;}if (first == list1.length) {for (int j = first + second; j < list1.length + list2.length; j++) {list[j] = list2[second++];}} else if (second == list2.length) {for (int j = first + second; j < list1.length + list2.length; j++) {list[j] = list1[first++];}}}return list;}}
0 0
- java语言程序设计第十版(Introduce to java 10th) 课后习题 chapter7-31
- java语言程序设计第十版(Introduce to java 10th) 课后习题 chapter7-21
- java语言程序设计第十版(Introduce to java 10th) 课后习题 chapter7-23
- java语言程序设计第十版(Introduce to java 10th) 课后习题 chapter7-24
- java语言程序设计第十版(Introduce to java 10th) 课后习题 chapter7-30
- java语言程序设计第十版(Introduce to java 10th) 课后习题 chapter7-32
- java语言程序设计第十版(Introduce to java 10th) 课后习题 chapter7-33
- java语言程序设计第十版(Introduce to java 10th) 课后习题 chapter6-31
- java语言程序设计第十版(Introduce to java 10th) 课后习题 chapter6-27
- java语言程序设计第十版(Introduce to java 10th) 课后习题 chapter6-28
- java语言程序设计第十版(Introduce to java 10th) 课后习题 chapter6-29
- java语言程序设计第十版(Introduce to java 10th) 课后习题 chapter6-30
- java语言程序设计第十版(Introduce to java 10th) 课后习题 chapter6-32
- java语言程序设计第十版(Introduce to java 10th) 课后习题 chapter12-11
- java语言程序设计第十版(Introduce to java) 课后习题 chapter6-10
- java语言程序设计第十版(Introduce to java) 课后习题 chapter6-6
- java语言程序设计第十版(Introduce to java) 课后习题 chapter6-13
- java语言程序设计第十版(Introduce to java) 课后习题 chapter6-14
- OC中的数组、字典、集合
- ( Leetcode 92 ) Reverse Linked List II
- BZOJ_P3944 Sum(数论+杜教筛)
- 二叉树的建立及层次遍历及前中后序遍历递归与非递归的实现
- Spark 性能相关参数配置详解-shuffle篇
- java语言程序设计第十版(Introduce to java 10th) 课后习题 chapter7-31
- 3.25
- char* 之间的赋值
- Ipad UISplitViewController
- <机器学习实战>配套资料
- SVN总结
- 懒加载
- C 总结——指针和数组是不同的两种东西
- CocoaPods报错:The dependency `AFNetworking ` is not used in any concrete target