惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

量子位
Stack Overflow Blog
Stack Overflow Blog
人人都是产品经理
人人都是产品经理
The GitHub Blog
The GitHub Blog
Engineering at Meta
Engineering at Meta
Vercel News
Vercel News
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Y
Y Combinator Blog
The Cloudflare Blog
Last Week in AI
Last Week in AI
B
Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
T
Tailwind CSS Blog
V
Visual Studio Blog
博客园 - 三生石上(FineUI控件)
小众软件
小众软件
Google DeepMind News
Google DeepMind News
D
DataBreaches.Net
博客园 - 司徒正美
B
Blog RSS Feed
Microsoft Azure Blog
Microsoft Azure Blog
罗磊的独立博客
Hugging Face - Blog
Hugging Face - Blog
L
LangChain Blog

博客园 - kenty06

LINQ 查询Select LINQ之DataContext 数据上下文 Dedecms57 分页 dede:pagelist 说明 window service服务安装错误 命名空间基础知识 - kenty06 - 博客园 C#简单类型转换说明 建立全文索引以及使用 Asp.net中防止用户多次登录的方法 VSS使用手册 开启全文索引 extJS初学小问题之js文件编码 - kenty06 - 博客园 VS2008加载包失败的解决方法 VS2005快捷键(转) 关于 odbc OdbcParameter参数问题 - kenty06 在 dotnet环境下使用 文件dsn - kenty06 关于枚举enum的tostring方法不能重写的一种替代方案 asp.net 2.0 学习点滴推荐(001) - kenty06 aspx页面事件顺序 - kenty06 - 博客园 C#中的default
希尔排序
kenty06 · 2010-02-05 · via 博客园 - kenty06

希尔排序

2010-02-05 07:01  kenty06  阅读(184)  评论()    收藏  举报

/// <summary>
    /// 希尔排序
    /// </summary>
    class ArraySh
    {
        private int[] theArray;
        private int nElems;
        public ArraySh(int max)
        {
            theArray = new int[max];
            nElems = 0;
        }
        public void Insert(int value)
        {
            theArray[nElems++] = value;
        }
        public void ShellSort()
        {
            int inner, outer;
            int temp;

            int h = 1;//计算间隔
            while (h <= nElems / 3)
                h = h * 3 + 1;

            while (h > 0)
            {
                for (outer = h; outer < nElems; outer++)
                {
                    temp = theArray[outer];
                    inner = outer;
                    while (inner > h - 1 && theArray[inner - h] >= temp)
                    {
                        //交换间隔值
                        theArray[inner] = theArray[inner - h];
                        inner -= h;
                    }
                    theArray[inner] = temp;
                }
                h = (h - 1) / 3;
            }
        }
    }