<span style="font-family: Arial; font-size: 14px; line-height: 26px;"> 折半排序法(二分插入排序法)</span><br style="font-family: Arial; font-size: 14px; line-height: 26px;" /><span style="font-family: Arial; font-size: 14px; line-height: 26px;">排序原理:其实也属于插入法类型,分已排序和未排序部分.然后将未排序</span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">部分元素逐个排序插入,但是插入的过程不同,需要每次求一个</span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">中间位置,和中间位置元素比较大小,然后根据大小情况,将高位</span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">左移或者将低位右移,再求中间元素比较,直到找到合适位置后,</span><span style="font-family: Arial; font-size: 14px; line-height: 26px;"> 将其后已排序元素全部后移一位,再插入该匀速即可.此方法中</span><span style="font-family: Arial; font-size: 14px; line-height: 26px;"> 每步打印的high和low关系应为high+1=low</span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">
</span>
public class ErFenSort {
public static void main(String[] args) {
int[] inte = { 3, 2, 5, 6, 0, 1, 9 };
erfenSort01(inte);
int len = inte.length;
for (int i = 0; i < len; i++) {
System.out.print(inte[i] + " ");
}
}
private static void erfenSort01(int[] inte) {
// TODO Auto-generated method stub
int low,mid,hight;
int temp;
for(int i=1;i<inte.length;i++){
temp=inte[i];
low=0;
hight=i-1;
while(low<=hight){
mid=(low+hight)/2;
if(inte[mid]>temp){
hight=mid-1;
}else{
low=mid+1;
}
}
for(int j=i-1;j>hight;j--){
inte[j+1]=inte[j];
}
inte[hight+1]=temp;
}
}
}