折半查找
来源:互联网 发布:t-sql语法基础知识 编辑:程序博客网 时间:2024/04/30 12:46
# include <stdio.h>/** * 时间:2016年6月5日 10:14:44 * 内容:折半查找 */int BinSearch(int*,int,int);void Info(int*,int);int main(void){int a[10]={2,1,4,3,5,6,11,9,0,7};Info(a,10);int num=BinSearch(a,10,6);printf("Final result = %d \n",num);return 0;}/** * 折半查找 * @param a 要查找的数组 * @param n 数组长度 * @param x 要查找的未知量 * @return 返回结果 */int BinSearch(int* a,int n,int x){int low,high,mid;low=0;high=n-1;while (low<=high){mid=(low+high)/2;if (x<a[mid]){high=mid-1;} else if (x>a[mid]){low=mid+1;}else return mid;}return -1;}void Info(int*a,int n){for (int i=0;i<n;i++){printf("%d ",a[i]);}printf("\n");}
0 0
- 折半查找
- 折半查找
- 折半查找
- 折半查找
- 折半查找
- 折半查找
- 折半查找
- 折半查找
- 折半查找
- 折半查找
- 折半查找
- 折半查找
- 折半查找
- 折半查找
- 折半查找
- 折半查找
- 折半查找
- 折半查找
- Leetcode Paint House
- POJ 3974 Palindrome manacher
- 怎么和自己喜欢的妹子聊天(吼吼吼,我怎么这么笨呢,啊啊啊)
- 《大数据精准挖掘》电信行业应用--客户流失预测
- 关于struts2访问servlet API的三种方法详解
- 折半查找
- 不用+、-、×、÷做加法
- Zephyr 教程:应用程序基础
- 《剑指offer》:[26]复杂链表的复制
- Entity Framework 之Code First自动数据迁移
- webstorm下载地址分享
- Java反射(一)
- 机器学习:LDA_数学基础_2:贝叶斯数学:先验分布的选择
- 游戏自动按键脚本2:海空战斗