3s8首页  | 新闻 | GIS | GPS | RS | 测绘测量 | 资料下载 | 开发语言 | 数据库 | CAD | 求职招聘 | 物流交通 | 论坛 | 博客 | RSS订阅 网站地图 
中国3S吧
首页 | | Java语言 | VC/VC.Net | VB/VB.Net | C/C++ | 书籍教程 |

C#四种排序算法


 日期:2006-12-28 论坛交流

本文检索关键字: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[i]>list[i+1])

{

done=false;

temp=list[i];

list[i]=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();

} }

}

中国3S吧 3s8.cn



选择排序

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[i];

list[i]=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();

} }

}


共2页: 上一页 1 [2] 下一页

上一篇:浅析.NET开发中代理模式的使用   下一篇:数据结构与算法(C#实现)系列---二叉堆(数组实现)



用户名: 新注册) 密码: 匿名评论 [所有评论]
评论内容:(不能超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规。