zoukankan      html  css  js  c++  java
  • 排序 二分插入法排序

    原文发布时间为:2009-03-06 —— 来源于本人的百度文章 [由搬家工具导入]

    using System;//二分插入排序
    namespace sorts
    {
       public class Class4
        {
           public static void Main()
           {
               int[] a = new int[] { 2, 12, 6, 5, 4, 3, 9 };
               BinSort(a);
               for (int i = 0; i < a.Length; i++)
                   Console.Write("{0} ", a[i]);
               Console.ReadLine();
           }

           public static void BinSort(int[] arr)
           {
               int left, right, mid, temp;

               for (int i = 1; i < arr.Length; i++)
               {
                   left = 0;
                   right = i - 1;
                   temp = arr[i];
                   while (left <= right)
                   {
                       mid = (left + right) >> 1;//(left + right)/2
                       if (temp < arr[mid]) //升序
                           right = mid - 1;
                       else
                           left = mid + 1;
                   }
                   for (int j = i - 1; j >= left; j--)
                       arr[j + 1] = arr[j];
                   arr[left] = temp;
               }
           }

        }
    }

  • 相关阅读:
    HTTP content-type
    python3学习--安装OCR识别库tesserocr
    http post get 类库 httphelper
    MD5
    解决python3中cv2读取中文路径的问题
    web api获得Post数据为空的解决办法
    python3项目打包成exe可执行程序
    pip install 使用国内镜像
    win10家庭版组策略安装
    在国企的日子(第七章 转正)
  • 原文地址:https://www.cnblogs.com/handboy/p/7153326.html
Copyright © 2011-2022 走看看