【第十三周项目1】验证算法--折半查找算法
来源:互联网 发布:p照片软件手机软件 编辑:程序博客网 时间:2024/06/06 00:26
/* * Copyright (c)2017,烟台大学计算机与控制工程学院 * All rights reserved. * 文件名称:折半查找算法.cpp * 作 者:swz* 完成日期:2017年11月29日 * 版 本 号:v1.0 * 问题描述:验证折半查找算法 * 输入描述:无 * 程序输出:测试数据 */ #include<iostream> using namespace std; int main() { int low=0,high,n; int a[100]; int i=0,f; cout<<"Please input the number of data and what data do you want to find"<<endl; while(cin>>n) { cin>>f; high=n-1; while(i<n) { cin>>a[i]; i++; } int mid; while(low<=high) { mid=(low+high)/2; if(a[mid]==f) { cout<<"find in the postion "<<mid+1<<endl; break; } if(a[mid]>f) { high=mid-1; } else { low=mid+1; } } if(low>high) { cout<<"can't find it"<<endl; } cout<<"Please input the number of data and what data do you want to find"<<endl; low=0; i=0; } return 0; }
阅读全文
0 0
- 【第十三周项目1】验证算法--折半查找算法
- 第十三周-验证折半查找的算法
- 第十三周项目一(1)——验证折半查找算法
- 第十三周项目一(1)——验证折半查找算法
- 第十三周——项目一—验证算法(1)线性表的折半查找
- 第十三周 项目一 验证算法 1.验证折半查找算法
- 第14周 项目1 - 验证算法 - 折半查找算法
- 【第十三周项目1】验证算法--分块查找算法
- 第14周 项目1-(1)验证折半查找算法
- 第14周项目1(1)验证折半查找算法
- 【第14周 项目1 - (1)验证折半查找算法】
- 第14周 项目1 - (1)验证折半查找算法
- 【第14周 项目1 - (1)验证折半查找算法】
- 第13周项目1- 验证折半查找算法(1)
- 第14周项目(1)-验证折半查找算法
- 第十三周 项目一 验证算法2. 分块查找算法
- 验证折半查找算法
- 验证折半查找算法
- JSON解析
- BimServerClient(BIM客户端)
- 一些VS2012常用的快捷键
- Maven:mirror(镜像)和repository(仓库) 区别
- 人脸识别之人脸对齐(八)--LBF算法
- 【第十三周项目1】验证算法--折半查找算法
- 第十二周 项目验证算法 (5)拓扑排序算法验证
- 在测试batik源码中的问题
- 两种方法上传本地文件到github
- 第十三周项目1-验证算法(2)
- STM8L15x系列DAC的使用
- [LeetCode] Intersection of Two Linked Lists
- 常用正则表达式
- JDBC插入Timestamp类型数据时精度问题