二分法查找折半查找(精)二分法查找折半查找(精)
#include
#define elemtype int
int sqsearch(elemtype a[],int n,elemtype x); //顺序查找 int sqsearch2(elemtype a[],int n,elemtype x); //顺序查找,打印查找过程 int binsearch(elemtype a[],int n,elemtype x); //折半查找 int binsearch2(elemtype a[],int n,elemtype x); //折半查找,打...
二分法查找折半查找(精)
#include
#define elemtype int
int sqsearch(elemtype a[],int n,elemtype x); //顺序查找 int sqsearch2(elemtype a[],int n,elemtype x); //顺序查找,打印查找过程 int binsearch(elemtype a[],int n,elemtype x); //折半查找 int binsearch2(elemtype a[],int n,elemtype x); //折半查找,打印查找过程
void printarray(elemtype a[],int n); //打印数组数据
int main()
{
int i,x;
const int n=9;
elemtype a1[10]={0,34,23,12,56,90,78,89,45,67};
elemtype a2[10]={0,12,23,34,45,56,67,78,89,90};
//顺序查找
cout<<"顺序查找,"<>x;
if((i=sqsearch(a1,n,x))>0) //找到
cout<<"找到x==a1["<>x;
if((i=binsearch(a2,n,x))>0) //找到
cout<<"找到x==a1["<x)
cout<"<"<
本文档为【二分法查找折半查找(精)】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑,
图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。