C语言合并数组
来源:互联网 发布:淘宝外卖红包免费领取 编辑:程序博客网 时间:2024/09/21 06:19
有两个升序的数组,合成一个非降序的数组
#include <stdio.h>
int main(int argc,const char * argv[]) {
// insert code here...
int a[] = {1,5, 7,9, 12,15, 19};
int b[] = {2,3, 6,8, 9};
int aCount =sizeof(a) / sizeof(a[0]);
int bCount =sizeof(b) / sizeof(b[0]);
int c[aCount + bCount];
int aPoint =0;
int bPoint =0;
for (int i =0; i < aCount + bCount; i++) {
if (aPoint > aCount -1) {
c[i] = b[bPoint];
bPoint++;
} elseif (bPoint > bCount - 1) {
c[i] = a[aPoint];
aPoint++;
} elseif (aPoint < aCount && a[aPoint] < b[bPoint]) {
c[i] = a[aPoint];
aPoint++;
} else {
c[i] = b[bPoint];
bPoint++;
}
}
for (int i =0; i < sizeof(c) /sizeof(c[0]); i++) {
printf("%d\t", c[i]);
}
return0;
}
- C语言合并数组
- C语言:合并数组
- C语言两数组合并
- C语言(8)--合并数组
- C语言实现:合并两个有序的数组,合并后的数组依然有序
- C语言合并两个数组并去重
- C语言用选择排序的方法合并有序数组
- C#byte数组合并
- 【C#】数组合并
- C 语言,将两个数组合并到另外一个数组中,并且合并之后的数组是有序的。
- 数组-数组合并(C版)
- 数组-数组合并(C版)
- C语言合并排序
- 【C语言】合并排序。
- c语言:字符串合并
- [c语言]将两个整形升序数组合并为一个升序数组
- 数据结构-数组排序(冒泡 选择 插入 归并(合并有序数组))-C语言
- C语言实现合并排序
- HDU1207:汉诺塔II
- 不读完你不会成功
- iOS崩溃 捕获异常处理
- java可视化编程-eclipse安装windowbuilder插件
- VMware安装的ubuntu下配置java环境
- C语言合并数组
- vim常用命令
- Unix环境高级编程-系统数据文件和信息
- java web 问题汇总
- Ubuntu Linux设置Open Files Limit和Max User Processes
- 下载测试版本cocoa pods,不建议使用
- 关于ping公司内网服务器ip,间歇性丢包的解决方案
- 用Eclipse和QT来编译Snort
- 十三、redis特性操作