public static void main(String[] args) {
// TODO Auto-generated method stub
int[] a ={65,23,68,45,2,1};
//冒泡排序;
/*for (int i = 0; i < a.length; i++) {
for (int j = 0; j < a.length-1-i; j++) {
if (a[j]>a[j+1]) {
int temp =a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}*/
//选择排序
/*int k;
for (int i = 0; i < a.length; i++) {
k=i;
for (int j = i+1; j < a.length; j++) {
if (a[k]<a[j]) {
k=j;
}
if (k==j) {
int temp =a[i];
a[i]=a[k];
a[k]=temp;
}
}
}*/
//折半查找法
int temp=68;
int lest=0;
int ringt=a.length-1;
int mid=0 ;
int flag=0;
while (flag==0 && lest<=ringt) {
mid = (lest+ringt)/2;
if (temp==a[mid]) {
flag=1;
}else if (temp<a[mid]) {
ringt=mid-1;
}else {
lest=mid+1;
}
}
// for (int i = 0; i < a.length; i++) {
// System.out.println(a[i]);
// }
System.out.println("在数组中下表是"+mid);
}
}