首页 > 试题广场 >

下面的程序是哪种排序? public class App {

[单选题]
下面的程序是哪种排序?
public class App {
public static void main(String[] args) {

    int [] a = {4,2,1,6,3,6,0,-5,1,1};
    int i,j;
    int low,high,mid;

    int temp;

    for(i=1;i<10;i++){
        temp=a[i];
        low=0;
        high=i-1;
        while(low<=high){
            mid=(low+high)/2;
            if(a[mid]>temp){
                high=mid-1;

            }else{
                low=mid+1;
            }


        }

        for(j=i-1;j>high;j--){
            a[j+1]= a[j];
            a[high+1] = temp;
        }


        for(i=0;i<10;i++){
            System.out.println(a[i]);
        }

    }


}
}
  • 归并排序
  • 快速排序
  • 希尔排序
  • 二分法排序
应该就是插入排序。插入过程使用了二分法查找,但因为查找到元素位置后还要将后面的元素移位,所以相比普通插入排序没什么优势
发表于 2017-11-23 23:21:04 回复(0)