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

推荐订阅源

Attack and Defense Labs
Attack and Defense Labs
The GitHub Blog
The GitHub Blog
C
Check Point Blog
博客园_首页
MongoDB | Blog
MongoDB | Blog
N
Netflix TechBlog - Medium
F
Full Disclosure
Microsoft Security Blog
Microsoft Security Blog
爱范儿
爱范儿
Recent Announcements
Recent Announcements
阮一峰的网络日志
阮一峰的网络日志
G
GRAHAM CLULEY
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
T
Threat Research - Cisco Blogs
C
Cybersecurity and Infrastructure Security Agency CISA
V
Vulnerabilities – Threatpost
K
Kaspersky official blog
博客园 - 司徒正美
S
Schneier on Security
T
The Exploit Database - CXSecurity.com
Project Zero
Project Zero
云风的 BLOG
云风的 BLOG
Cisco Talos Blog
Cisco Talos Blog
Know Your Adversary
Know Your Adversary
雷峰网
雷峰网
V
V2EX - 技术
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Spread Privacy
Spread Privacy
罗磊的独立博客
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
S
Security Affairs
SecWiki News
SecWiki News
Schneier on Security
Schneier on Security
O
OpenAI News
Jina AI
Jina AI
PCI Perspectives
PCI Perspectives
Cyberwarzone
Cyberwarzone
Y
Y Combinator Blog
Apple Machine Learning Research
Apple Machine Learning Research
B
Blog RSS Feed
I
InfoQ
D
Docker
P
Palo Alto Networks Blog
Recorded Future
Recorded Future
M
MIT News - Artificial intelligence
博客园 - Franky
B
Blog
Scott Helme
Scott Helme
博客园 - 叶小钗
D
DataBreaches.Net

博客园 - 雨衣blog

windows 7 下安装 IIS 和 ArcGis Server 9.3 遇到的问题及解决方法 win7 64位系统使用VS2010生成时出现中文目录乱码问题的解决方法【转】 const和static readonly区别 笔记本商家 辅食 博文阅读密码验证 - 博客园 博文阅读密码验证 - 博客园 博文阅读密码验证 - 博客园 博文阅读密码验证 - 博客园 如何修改 VS2010 的 HelpLibrary(即MSDN)的安装路径 DevExpress控件使用 - 雨衣blog - 博客园 Java设计模式之综述篇 通过拦截器来统计每个action的执行时间 二分法快速查找的递归算法 C#编码好习惯 xml操作类 - 雨衣blog - 博客园 认识oracle数据类型 在sqlplus中查看 open_cursors的数值: c#获取本机IP,机器名,然后是操作系统版本 - 雨衣blog - 博客园
C#四种排序算法
雨衣blog · 2009-01-03 · via 博客园 - 雨衣blog

C#四种排序算法

冒泡排序

using System;namespace BubbleSorter { public class BubbleSorter { public void Sort(int [] list) { int i,j,temp; bool done=false; j=1; while((j<list.Length)&&(!done)) { done=true; for(i=0;i<list.Length-j;i++) { if(list>list[i+1]) { done=false; temp=list; list=list[i+1]; list[i+1]=temp; } } j++; } } } public class MainClass { public static void Main() { int[] iArrary=new int[]{1,5,13,6,10,55,99,2,87,12,34,75,33,47}; BubbleSorter sh=new BubbleSorter(); sh.Sort(iArrary); for(int m=0;m<iArrary.Length;m++) Console.Write("{0} ",iArrary[m]); Console.WriteLine(); } } }

选择排序

using System; namespace SelectionSorter { public class SelectionSorter { private int min; public void Sort(int [] list) { for(int i=0;i<list.Length-1;i++) { min=i; for(int j=i+1;j<list.Length;j++) { if(list[j]<list[min]) min=j; } int t=list[min]; list[min]=list; list=t; } } } public class MainClass { public static void Main() { int[] iArrary=new int[]{1,5,3,6,10,55,9,2,87,12,34,75,33,47}; SelectionSorter ss=new SelectionSorter(); ss.Sort(iArrary); for(int m=0;m<iArrary.Length;m++) Console.Write("{0} ",iArrary[m]); Console.WriteLine(); } } }

插入排序

using System;

namespace InsertionSorter {

 public class InsertionSorter

 {

 public void Sort(int [] list)

 {

 for(int i=1;i<list.Length;i++)

{ int t=list;

 int j=i;

while((j>0)&&(list[j-1]>t))

 {

list[j]=list[j-1]; --j;

 }

 list[j]=t;

 }

}

}

public class MainClass {

 public static void Main()

{

 int[] iArrary=new int[]{1,13,3,6,10,55,98,2,87,12,34,75,33,47};

 InsertionSorter ii=new InsertionSorter();

 ii.Sort(iArrary);

 for(int m=0;m<iArrary.Length;m++)

 Console.Write("{0}",iArrary[m]);

Console.WriteLine();

 }

 }

}

希尔排序

希尔排序是将组分段,进行插入排序。

using System; namespace ShellSorter { public class ShellSorter { public void Sort(int [] list) { int inc; for(inc=1;inc<=list.Length/9;inc=3*inc+1); for(;inc>0;inc/=3) { for(int i=inc+1;i<=list.Length;i+=inc) { int t=list[i-1]; int j=i; while((j>inc)&&(list[j-inc-1]>t)) { list[j-1]=list[j-inc-1]; j-=inc; } list[j-1]=t; } } } } public class MainClass { public static void Main() { int[] iArrary=new int[]{1,5,13,6,10,55,99,2,87,12,34,75,33,47}; ShellSorter sh=new ShellSorter(); sh.Sort(iArrary); for(int m=0;m<iArrary.Length;m++) Console.Write("{0} ",iArrary[m]); Console.WriteLine(); } } }