排序算法比较 C#排序算法大全
C#排序算法大全
冒泡排序 学语言要花大力气学数据结构和算法 using Systemnamespace BubbleSorter { public class BubbleSorter { public void Sort(int [] list) { int i j temp bool done=false j= while((j<list Length)&&(!done)) { done=true for(i= i<list Length j i++) { if(list[i]>list[i+ ]) { done=false temp=list[i] list[i]=list[i+ ] list[i+ ]=temp } } j++ }
} } public class MainClass { public static void Main() { int[] iArrary=new int[]{ } BubbleSorter sh=new BubbleSorter() sh Sort(iArrary) for(int m= m<iArrary Length m++) Console Write( { } iArrary[m]) Console WriteLine() } } }

选择排序
本人用了C#开发出选择排序算法 希望能为C#语言的学习者带来一些益处 不要忘了 学语言要花大力气学数据结构和算法
using System
namespace SelectionSorter { public class SelectionSorter { private int min public void Sort(int [] list) { for(int i= i<list Length i++) { min=i for(int j=i+ j<list Length j++) { if(list[j]<list[min]) min=j } int t=list[min] list[min]=list[i] list[i]=t }
} } public class MainClass { public static void Main() { int[] iArrary=new int[]{ } SelectionSorter ss=new SelectionSorter() ss Sort(iArrary) for(int m= m<iArrary Length m++) Console Write( { } iArrary[m]) Console WriteLine()
} } }
插入排序
插入排序算法 对想提高C#语言编程能力的朋友 我们可以互相探讨一下 如 下面的程序 并没有实现多态 来 帮它实现一下
using System
namespace InsertionSorter { public class InsertionSorter { public void Sort(int [] list) { for(int i= i<list Length i++) { int t=list[i] int j=i while((j> )&&(list[j ]>t)) { list[j]=list[j ] j } list[j]=t }
} } public class MainClass { public static void Main() { int[] iArrary=new int[]{ } InsertionSorter ii=new InsertionSorter() ii Sort(iArrary) for(int m= m<iArrary Length m++) Console Write( { } iArrary[m]) Console WriteLine() } } }
希尔排序 希尔排序是将组分段 进行插入排序 对想提高C#语言编程能力的朋友 我们可以互相探讨一下 如 下面的程序 并没有实现多态 来 帮它实现一下
using System
lishixinzhi/Article/program/net/201311/11523