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

        }
    }

  • 相关阅读:
    Java中的权限修饰符
    return,break,continue三者的区别
    JS代码放在不同位置的区别
    创建画笔工具
    关于SPH的核函数求导过程
    c++多级指针与“多维”数组 摘自别人博客
    RAP开发入门-搭建RAP开发环境(一)
    06 media媒体查询
    resolution 像素密度
    手动配置viewport-04
  • 原文地址:https://www.cnblogs.com/handboy/p/7153326.html
Copyright © 2011-2022 走看看