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];

        }

    }

  • 相关阅读:
    3.21上午
    3.17下午
    2017.4.14-morning
    2017.4.13-afternoon
    2017.4.13-morning
    2017.4.12-afternoon
    2017.4.12-morning
    2017.4.11-afternoon
    2017.4.11-morning
    2017.4.10-afternoon
  • 原文地址:https://www.cnblogs.com/jinhengyu/p/7516539.html
Copyright © 2011-2022 走看看