zoukankan      html  css  js  c++  java
  • 算法之【折半插入法】

    折半插入排序(binary insertion sort)是对插入排序算法的一种改进,采用二分法进行比较时不用一个一个比,而是”跳着选”的方式.

    Java算法原型:

    void BinaryInsertSort(int R[],int n )

    {

        int i,j,mid,low,high,temp;

        for(i=2; i<=n; ++i)

        {

            R[0] = R[i];

            low = 1;

            high = i-1;

            while(low <= high)

            {

                mid = (low + high) / 2;

                if(temp > R[mid])

                {

                    low = mid + 1;

                }else{

                    high = mid - 1;

                }

            }

            for(j=i-1; j>=high+1; --j)

            {

                R[j+1] = R[j];

            }

            R[high+1] = R[0];

        }

    }

  • 相关阅读:
    LINUX学习笔记day2
    android 获取正在运行的服务
    android小部件
    android开发_国外论坛
    取消线程
    AlarmManager的使用
    PendingIntent
    SharedPreferences 的使用
    流量监听
    android 异常-access to constructor not allowed
  • 原文地址:https://www.cnblogs.com/jinhengyu/p/7516539.html
Copyright © 2011-2022 走看看