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

推荐订阅源

A
About on SuperTechFans
人人都是产品经理
人人都是产品经理
量子位
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 三生石上(FineUI控件)
小众软件
小众软件
月光博客
月光博客
T
Tailwind CSS Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
V
Visual Studio Blog
博客园 - 叶小钗
博客园 - 司徒正美
美团技术团队
博客园_首页
宝玉的分享
宝玉的分享
Apple Machine Learning Research
Apple Machine Learning Research
Hugging Face - Blog
Hugging Face - Blog
WordPress大学
WordPress大学
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
The Cloudflare Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
有赞技术团队
有赞技术团队
D
DataBreaches.Net
Google DeepMind News
Google DeepMind News

博客园 - smallnest

希尔排序 插入排序 Gnome sort 鸡尾酒排序 奇偶排序 快速排序 冒泡排序 algorithm in c# 开发人员最喜爱的十大免费的Visual Studio插件(下) 开发人员最喜爱的十大免费的Visual Studio插件(上) 一种获取重载泛型方法的方式 [游戏]五子连珠 发布一个记账软件---流水记账 轻松编写您自己的拖拉机算法,进行算法大战 拖拉机大战更新了 拖拉机大战1.1.0.320发布,更多新功能 拖拉机大战新春贺岁版发布 翻译助手0.1 visual studio 2005 常用类型的图标
Comb排序
smallnest · 2009-12-19 · via 博客园 - smallnest

类别:排序-交换排序
参看 维基百科的定义

1 using System;
2  using System.Collections.Generic;
3
4 namespace Com.Colobu.Algorithm.Exchange
5 {
6 /// <summary>
7 /// <b>Comb sort</b> improves on bubble sort, and rivals algorithms like Quicksort.
8 /// The basic idea is to eliminate turtles, or small values near the end of the list,
9 /// since in a bubble sort these slow the sorting down tremendously.
10 ///
11 /// 平均时间复杂度:O(nlogn)
12 /// Stability:No
13 /// </summary>
14 public class CombSortAlgorithm
15 {
16 public static void CombSort<T>(IList<T> szArray) where T : IComparable
17 {
18 int gap = szArray.Count;
19 bool swapped = true;
20
21 while (gap > 1 || swapped)
22 {
23 if (gap > 1)
24 {
25 gap = (int)(gap / 1.25);
26 }
27
28 int i = 0;
29 swapped = false;
30 while (i + gap < szArray.Count)
31 {
32 if (szArray[i].CompareTo(szArray[i + gap]) > 0)
33 {
34 T t = szArray[i];
35 szArray[i] = szArray[i + gap];
36 szArray[i + gap] = t;
37 swapped = true;
38 }
39 i++;
40 }
41 }
42 }
43 }
44 }
45