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

        }
    }

  • 相关阅读:
    getchar,putchar函数
    强制类型转换和整数常量的数据类型及转换
    c语言整型的隐式数据 类型转换
    c语言整型数据输出格式声明
    c语言整型变量的储存空间,以及所表示的整数范围
    c语言常量
    c语言求回文数
    Android4.0源码目录结构详解
    MTK Android源代码目录
    Comparator 和 Comparable
  • 原文地址:https://www.cnblogs.com/handboy/p/7153326.html
Copyright © 2011-2022 走看看