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

推荐订阅源

Blog — PlanetScale
Blog — PlanetScale
N
Netflix TechBlog - Medium
博客园 - 司徒正美
The GitHub Blog
The GitHub Blog
G
Google Developers Blog
Stack Overflow Blog
Stack Overflow Blog
博客园_首页
Google DeepMind News
Google DeepMind News
博客园 - 【当耐特】
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Recent Announcements
Recent Announcements
aimingoo的专栏
aimingoo的专栏
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Y
Y Combinator Blog
B
Blog RSS Feed
人人都是产品经理
人人都是产品经理
MongoDB | Blog
MongoDB | Blog
量子位
博客园 - Franky
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
The Cloudflare Blog
有赞技术团队
有赞技术团队
Jina AI
Jina AI
GbyAI
GbyAI

博客园 - 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;
            }
        }
    }