package com.sksort;
public class insert_Binary {
public static void main(String[] args) {
int a[] = {5,5,4,5,2,1,8,0,5,9};
insert_Binary s = new insert_Binary();
s.sort(a);
s.show(a);
}
public void sort(int a[]) {
int i, j ,temp, low, high, mid = 0;
for (i = 1; i < a.length; i++)
if (a[i] < a[i-1]) {
temp = a[i];
low = 0;
high = i - 1;
while (low < high) {
mid = (low + high) / 2;
if(temp == a[mid]){
low = mid+1;
break;
}
else if (temp > a[mid])
low = mid+1 ;
else
high = mid-1 ;
}
for (j = i; j > low; j--)
a[j] = a[j-1];
a[low] = temp;
}
}
public void show(int a[]) {
for (int i = 0; i < a.length; i++) {
if (i == 0)
System.out.print(a[i]);
else
System.out.print(" " + a[i]);
}
System.out.println();
}
}
插入类------二分插入排序
最新推荐文章于 2022-06-12 13:14:16 发布