查找循环数组最小值
package searcharrary;
//查找循环数组最小值
class SearchMin{
public int search(int[] data) {
int l=0;
int r=data.length-1;
int m=0;
if(data[l]<data[r]) {
return data[l];
}
while(l+1!=r) {
m=(r+l)/2;
if(data[l]>data[m]) {
r=m;
}
if(data[m]>data[r]) {
l=m;
}
if(data[l]==data[m]&&data[m]==data[r]) {
int min=data[0];
for(int i=1;i<data.length;i++) {
if(data[i]<min)
min=data[i];
}
return min;
}
}
return data[l+1];
}
}
public class SearchCir {
public static void main(String[] args) {
int[] data=new int[] {7,8,1,2,3,4,5,6};
SearchMin sm=new SearchMin();
System.out.println(sm.search(data));
}
}