博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
算法实验1 两个数组的中位数
阅读量:7075 次
发布时间:2019-06-28

本文共 775 字,大约阅读时间需要 2 分钟。

// test.cpp: 定义控制台应用程序的入口点。//#include "stdafx.h"#include
#include
using namespace std;int midSearch(int a[], int b[],int na,int nb) { int a_l = na; int b_l = nb; int *temp = new int[a_l + b_l + 1]; int i = 0, j = 0, t = 0; while (i < a_l && j < b_l) { if (a[i] <= b[j])temp[t++] = a[i++]; else temp[t++] = b[j++]; } while (i < a_l)temp[t++] = a[i++]; while (j < b_l)temp[t++] = b[j++]; //for (int i = 0; i < a_l + b_l; i++)cout << temp[i]; int l = a_l + b_l; if (l % 2 == 0) return((temp[l / 2-1] + temp[l / 2 ]) / 2);//注意数组下标从0开始 else return(temp[l / 2 ]); }int main(){ int a[] = { 1,2,3 }; int b[] = { 4,5}; cout<

 

转载于:https://www.cnblogs.com/ZengWeiHao/p/10450639.html

你可能感兴趣的文章
减少Linux 电耗 转自IBM
查看>>
新的一年又开始了,加油2013!
查看>>
Sharepoint学习笔记—习题系列--70-573习题解析 -(Q22-Q24)
查看>>
ios block循环引用问题
查看>>
地图覆盖物
查看>>
项目中出现黄色感叹号 教你去掉Myeclipse的黄色感叹号
查看>>
python手记(9)
查看>>
hdu 2451 Simple Addition Expression(数位DP )成败在于细节
查看>>
在开机广播中启动服务
查看>>
poj1077
查看>>
第二步 (仅供参考) sencha touch 使用cmd打包apk
查看>>
ios测试宏指令出错:“Expected identefier”
查看>>
.Net开发笔记(二十)创建一个需要授权的第三方组件
查看>>
_tfopen 打开文件
查看>>
SharePoint如何模拟用户
查看>>
ORACLE删除字段(set unused的用法)
查看>>
根正苗红_百度百科
查看>>
java 获取获取字符串编码格式
查看>>
I/O复用
查看>>
将数据加载时显示的图片和文字提成公共的--实现方法
查看>>