package sort;
public class Test53_2 {
public static void main(String[] args) {
int[]a={0,1,2,3,5,6,7};
System.out.println(getFirstDisorder2(a));
}
public static int getFirstDieorder(int[]a,int from,int to){
int mid=(from+to)>>>1;
if(mid==a[mid]){
from=mid+1;
}
if(mid<a[mid]){
if(mid==0||(mid-1)==a[mid-1]){
return mid;
}else{
to=mid-1;
}
}
return getFirstDieorder(a, from, to);
}
public static int getFirstDisorder2(int[]a){
int low=0;
int high=a.length-1;
while(low<=high){
int mid=(low+high)>>>1;
if(mid==a[mid]){
low=mid+1;
}
if(mid<a[mid]){
if(mid==0||(mid-1)==a[mid-1]){
return mid;
}else{
high=mid-1;
}
}
}
return -1;
}
}