package Algorithm.binarysearchnorecursion;public class BinaaySearchNoRecur {public static void main(String[] args) {int arr [] = {1,2,3,4,5};int b = binarySearch(arr, 0);System.out.println(b);}//二分查找的非递归实现public static int binarySearch(int [] arr, int target){int left = 0;int right = arr.length - 1;boolean flag = true;while(left <= right){int mid = (left + right) / 2;if (target == arr[mid]){return mid;}if (target > arr[mid]){left = mid + 1;}else {right = mid - 1;}}return -1;}
}