zoukankan      html  css  js  c++  java
  • 希尔排序_排序算法_算法

    总感觉有点问题,是不是写错了

     #region 希尔排序
            public static void Main()
            {
                int[] array = { 6, 1, 4, 5, 0, 7, 2, 3, 9, 8, 23, 56, 89, 4, 56 };
                Sort(array);
                for (int i = 0; i < array.Length; i++)
                {
                    Console.WriteLine(array[i]);
                }
                Console.ReadKey();
    
            }
            public static void Sort(int []array)
            {
                int count = array.Length / 2;
                int temp=0;
                int n = 0;
                for (int i=count;i>=1 ;i-- )
                {
                    for (int j = 0; j+i<array.Length; j++)
                    {
                        if (array[j] > array[j + i])
                        {
                            temp = array[j];
                            array[j] = array[j + i];
                            array[j + i] = temp;
                        }
                        n++;
                    }
                   
                }
                Console.WriteLine("run:"+n);
            }
            #endregion
     
     
    修改后的希尔排序:
     public static void Main()
            {
                //int[] array = { 6, 1, 4, 5, 0, 7, 2, 3, 9, 8, 23, 56, 89, 4, 56 };
                int temp = 0;
                int t = 0;
                     int num=0;
                for (int n = array.Length / 2; n > 0;n = n/2 )
                {
    
                    for (int j = n; j <array.Length;j++ )
                    {
                        t=j;
                        while (t - n >= 0)
                        {
                            if (array[t] < array[t - n])
                            {
                                temp = array[t-n];
                                array[t - n] = array[t];
                                array[t] = temp;
                            }
                            t = t - n;
                        }
                    }
                }
                for (int i = 0; i < array.Length; i++)
                {
                    Console.WriteLine(array[i]);
                }
                Console.ReadKey();
    
            }
  • 相关阅读:
    二分查找法的实现和应用汇总
    hdu 3062 Party 2SAT入门
    network monitor 抓包软件 微软的 架构师提供的
    富文本编辑器
    分享图标
    js日期时间控件
    jquery form
    javascript学习站
    sql生成model类
    PHP学习
  • 原文地址:https://www.cnblogs.com/steben/p/3107304.html
Copyright © 2011-2022 走看看