折半查找
来源:互联网 发布:macbook要下什么软件 编辑:程序博客网 时间:2024/05/22 06:44
偶然看到的记录下,写的很好
private static int binarySearch(int[] a, int start, int len, int key) {
int high = start + len, low = start - 1, guess;
while (high - low > 1) {
guess = (high + low) / 2;
if (a[guess] < key)
low = guess;
else
high = guess;
}
if (high == start + len)
return ~(start + len);
else if (a[high] == key)
return high;
else
return ~high;
}
int high = start + len, low = start - 1, guess;
while (high - low > 1) {
guess = (high + low) / 2;
if (a[guess] < key)
low = guess;
else
high = guess;
}
if (high == start + len)
return ~(start + len);
else if (a[high] == key)
return high;
else
return ~high;
}
- 折半查找
- 折半查找
- 折半查找
- 折半查找
- 折半查找
- 折半查找
- 折半查找
- 折半查找
- 折半查找
- 折半查找
- 折半查找
- 折半查找
- 折半查找
- 折半查找
- 折半查找
- 折半查找
- 折半查找
- 折半查找
- How to Push a New Local Branch to a Remote Git Repository
- 分享算法小魅力
- Linux tcpdump命令详解
- Interactive Python:Mini-project #8 - RiceRocks (Asteroids)
- kettle ETL java 调用 kettle job 或 transfer
- 折半查找
- 学习网站总结
- ibatis学习 : xml配置 -- 级联查询
- tcpdump抓包分析详解
- iReport 子报表的数据源 设置
- OpenCV中读取RGB格式图像转成HSV格式图像显示
- mfc连接access
- 如何查看系统历史开关机时间
- return confirm Cannot return from outside a function or method