public static int PaiXu(int[]arr,int a){
// return Demo1(arr, a);
// return Demo2(arr, a);
int min =0;
int max=arr.length-1;
int mid=(min+max)/2;
while(arr[mid]!=a){
if (arr[mid]>a) {
max=mid-1;
}else if (arr[mid]<a) {
min=mid+1;
}
mid=(min+max)/2;
if (min>max) {
return -1;
}
}
return mid;
}
private static int Demo2(int[] arr, int a) {
int min=0;
int max=arr.length-1;
int mid=(max+min)/2;
while(arr[mid]!=a){
if (arr[mid] > a) {
max=mid-1;
}else if (arr[mid]<a) {
min=mid+1;
}
mid=(max+min)/2;
if (min>max) {
return -1;
}
}
return mid;
}
private static int Demo1(int[] arr, int a) {
int min=0;
int max=arr.length-1;
int mid=(max+min)/2;
while (arr[mid]!=a) {
if (arr[mid]>a) {
max=mid-1;
}else if (arr[mid]<a) {
min=mid+1;
}
mid=(max+min)/2;
if (min>max) {
return -1;
}
}