zoukankan      html  css  js  c++  java
  • 希尔排序(C#数据结构学习八)

    using System;
    using System.Collections.Generic;
    using System.Text;

    namespace SoloDataStructure
    {
        
    class MyShellSort
        
    {
              
    /// <summary>
              
    /// 希尔排序
              
    /// </summary>
              
    /// <param name="arr">需要排序的数列</param>

           static  void ShellSort (int[] arr)
             
    {
                 
    int temp; //
                 int n = arr.Length;
                 
    int gap = n / 2//初始步长
                 while (gap != 0)
                 
    {
                     
    for (int i = gap; i < arr.Length; i++)
                     
    {
                         
    int j;
                         temp
    =arr[i];
                         
    for (j = i; j >= gap; j = j - gap)  //同子序列的插入排序
                         {
                             
    if (temp < arr[j - gap])
                                 arr[j] 
    = arr[j - gap]; //如果后面的小于前面的,交换位置
                             else
                                 
    break;
                         }

                             arr[j] 
    = temp;            //插入      
                     }

                         gap 
    /= 2//缩短步长
                 }


             }
                
            
    static void Main(string[] args)
            
    {
        
                
    int[] arr = new int[] 99,198,97,96,905,44,93,2,91};
                Console.Write(
    "希尔排序前:");
                
    for (int i = 0; i < arr.Length; i++)
                    Console.Write(arr[i] 
    + ".");
                ShellSort(arr);
                Console.Write(
    "\n希尔排序后:");
                
    for (int i = 0; i < arr.Length; i++)
                    Console.Write(arr[i]
    +".");
                 
                Console.ReadLine();
            }

        }

    }
  • 相关阅读:
    今日确定开源近两年来的EA程序
    升级了NinjaLoveFish Excel量化表格
    到家第一件事就是脱衣服
    对挑选完成的股票,进行批量建仓
    lua 学习之错误处理
    lua 学习之编译
    Lambda 演算入门
    lua学习之深入函数第二篇
    lua学习之深入函数第一篇
    lua学习之复习汇总篇
  • 原文地址:https://www.cnblogs.com/solo/p/609674.html
Copyright © 2011-2022 走看看