- package per;
- public class Array1 {
- public int find(int searchKey, int[] array) {
- int lowBound = 0;
- int uppBound = array.length - 1;
- int curIndex;
- while (true) {
- curIndex = (lowBound + uppBound) / 2;
- if (array[curIndex] == searchKey) { <
数据结构二分法
最新推荐文章于 2023-12-27 18:14:06 发布
这是一个Java实现的二分查找算法,通过不断缩小搜索范围,直到找到目标值或者搜索区间变为0。如果找到目标值,返回其在数组中的下标;否则,返回-1表示未找到。
摘要由CSDN通过智能技术生成