知识大全 C#排序算法大全
Posted 语言
篇首语:如果不想在世界上虚度一生,那就要学习一辈子。本文由小常识网(cha138.com)小编为大家整理,主要介绍了知识大全 C#排序算法大全相关的知识,希望对你有一定的参考价值。
C#排序算法大全 以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!
冒泡排序 学语言要花大力气学数据结构和算法 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
cha138/Article/program/net/201311/11523相关参考