Java 二分冒泡排序算法
public void Sort(int a[]) {
int temp, j;
int num[] = a;
boolean flag;
flag = true;
j = 0;
while (flag) {
flag = false;
for (int i = 0; i < num.length – 1 – j; i++) {
if (num[i] > num[i + 1]) {
temp = num[i];
num[i] = num[i + 1];
num[i + 1] = temp;
flag = true;
}
}
j++;
}
// System.out.print(num[3]);
}
public int Found(int a[], int r) {
int start, end, middle, rs;
start = 0;
end = a.length;
rs = r;
while (start < end) {
middle = (start + end) / 2;
if (rs == a[middle]) {
return middle;
}
if (rs < a[middle]) {
end = middle-1;
}
if (rs > a[middle]) {
start = middle+1;
}
}
return -1;
}