实验 折半查找算法
来源:互联网 发布:php 开源网盘系统 编辑:程序博客网 时间:2024/05/22 10:31
掌握折半查找算法的思想及程序实现。
代码:
#include <bits/stdc++.h>using namespace std;typedef struct BSearch{ int elem[20];public: void ini(){ for(int i=0;i<20;i++) elem[i]=rand()%91; sort(elem,elem+20); } int Find(int x){ int l=0,r=19,mid; while(l+1<=r){ mid=(l+r)/2; if(elem[mid]<x){ l=mid+1; }else r=mid; } return l; } void show(){ for(int i=0;i<20;i++) cout<<elem[i]<<' '; cout<<endl; }}BSearch;int main(){ srand((unsigned long long)time(0)); BSearch a; a.ini(); a.show(); int x,t; while(cin>>x){ cout<<a.Find(x)<<endl; }}
阅读全文
0 0
- 实验 折半查找算法
- 查找算法 折半查找算法
- 折半查找算法示例
- 折半查找算法实现
- 算法-折半查找
- 折半查找算法
- 折半查找算法
- 算法:折半查找法
- 折半查找算法
- 折半查找算法
- 验证折半查找算法
- 验证折半查找算法
- 验证折半查找算法
- 折半查找(递归算法)
- 关于折半查找算法
- 折半查找算法
- [算法]折半查找
- 折半查找算法
- 数据结构----插入排序
- Ctrl键组合
- 解决Android Studio 新建导入项目时死掉
- postgresql与Oracle:空字符串与null
- 35. Search Insert Position
- 实验 折半查找算法
- setInterval第一个参数加引号与不加引号区别
- Android图片加载-TakePhoto
- java 获取当前类的所有父类
- 【0018】navicat导出sql语句
- OpenSSL 静态、共享编译,解决ms\do_ms报错
- 【vmware 服务器安装】虚拟机centos6.5安装步骤
- 对json数组进行排序和filter过滤
- Bytes2HexStr与hexStr2Bytes