标题: 折半查找 [打印本页] 作者: gss 时间: 2015-9-22 22:43 标题: 折半查找 public class ArryToString2 {
public static void main(String[] args) {
int arr[]={23,45,56,67,78,90};
int key=searchSort(arr,57);
System.out.println(key);
}
public static int searchSort(int arr[],int key) {
int min=0,max=arr.length-1;
int mid=0;
mid=(min+max)/2;
//for (int i = 0; i < arr.length; i++) {
while(arr[mid]!=key){
if(key>arr[mid]){
min=mid+1;
}
else if(key<arr[max]){
max=mid-1;