【C/C++】merge two array by order
来源:互联网 发布:java 图片上传 编辑:程序博客网 时间:2024/06/05 14:07
#include "stdio.h"void show(int a[],int len) {int i;for (i = 0; i < len; i++) {printf("%d-", a[i]);}printf("\n");}void merge(int arr1[], int arr2[], int res[]) {printf("before merge:\n");show(arr1,10);show(arr2,10);int i=0, j=0;int idx = 0;for (;;) {printf("show res:");show(res,20);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;}int main() {int arr1[10] = { 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };int arr2[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };int res[20]={0};int size = sizeof(res)/4;printf("res size:%d\n",size);merge(arr1, arr2, res);printf("final:");show(res,20);return 0;}refer to :http://blog.csdn.net/xiewenbo/article/details/34419435
0 0
- 【C/C++】merge two array by order
- 【JAVA】merge two array by order
- Merge Two Sorted Lists(C++)
- Merge two sorted Array
- [C++]LeetCode: 13 Merge Two Sorted Lists
- 【leetcode c++】21 Merge Two Sorted Lists
- 【LeetCode-21】 Merge Two Sorted Lists(C++)
- Leetcode 21. Merge Two Sorted Lists(C++)
- 【C++】【LeetCode】21. Merge Two Sorted Lists
- LeetCode 617. Merge Two Binary Trees (C++)
- Leetcode c语言- Merge Two Sorted Lists
- [C++]LeetCode: 10 Merge Sorted Array
- [leetcode-88]Merge Sorted Array(C语言)
- 【leetcode c++】88 Merge Sorted Array
- [C语言][LeetCode][88]Merge Sorted Array
- [leetcode]Merge Sorted Array C语言
- 【LeetCode-88】Merge Sorted Array(C++)
- Leetcode 88. Merge Sorted Array with C
- Fedora 20: How to enable SSH
- 设计模式(3)——观察者模式(Observer Pattern)
- DecimalFormat用法
- 分享一个链接
- 解决StaggeredGridView加载更多滑到顶部的问题
- 【C/C++】merge two array by order
- Mysql安装配置及常用操作
- Ant学习笔记
- PHPxampp安装
- jsp页面中实现复选框全选和反选、选中删除功能
- java java.lang.NoClassDefFoundError 的解决办法
- C Tips:显示点阵汉字的小例子
- .NET如何处理AJAX传入的JSON数据
- 我是一兼S的地方细绳自偷窘