package com.jrpay;public class Test2 {
public static void binary_sort(int a[])
{
int i,j,temp;
int low ,hight ,mid;
for(i=1;i<a.length;i++)
{
temp = a[i];
low = 0;
hight = i-1;
while(low<=hight)
{
mid = (low+hight)/2;
if(a[mid]>temp)
hight =mid -1;
else
low = mid + 1;
}
for(j =i-1;j>hight;j--) 这里三行代码看不懂是什么意思,能为我解释一下吗,详细点,谢谢。
a[j+1] = a[j];
a[hight+1] = temp;
}
}
public static void main(String[] args) {
int a[] = {2,6,9,8,4,7,3,1,0,5};
binary_sort(a);
for(int i=0;i<a.length;i++)
System.out.print(a[i]+ " ");
}
}
public static void binary_sort(int a[])
{
int i,j,temp;
int low ,hight ,mid;
for(i=1;i<a.length;i++)
{
temp = a[i];
low = 0;
hight = i-1;
while(low<=hight)
{
mid = (low+hight)/2;
if(a[mid]>temp)
hight =mid -1;
else
low = mid + 1;
}
for(j =i-1;j>hight;j--) 这里三行代码看不懂是什么意思,能为我解释一下吗,详细点,谢谢。
a[j+1] = a[j];
a[hight+1] = temp;
}
}
public static void main(String[] args) {
int a[] = {2,6,9,8,4,7,3,1,0,5};
binary_sort(a);
for(int i=0;i<a.length;i++)
System.out.print(a[i]+ " ");
}
}
//这个循环的作用是插入数据 上面的循环是为了找到插入位置
for(j =i-1;j>hight;j--)
a[j+1] = a[j]; //hight下标的地方是数据取出的地方,把应该插入数据的地方到 数据取出的地方的数据都向后挪一个位置
a[hight+1] = temp; //这个语句为了插入数据