请用C#编写一个冒泡排序算法,立即给分!

chinaraul 2003-08-02 10:38:33
用C#语法编写冒泡排序或是选择排序也行(得建类),率先答出者马上送分!
...全文
453 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
chinaraul 2003-08-02
  • 打赏
  • 举报
回复
班门斧,你真厉害!
baisun 2003-08-02
  • 打赏
  • 举报
回复
that's OK!
TheAres 2003-08-02
  • 打赏
  • 举报
回复
using System;
namespace SelectSorter
{


public class SelectSorter
{
public void Sort( int[] list )
{
int tmp;
for( int i = 0; i < list.Length; i++ )
{
for( int j = i + 1; j < list.Length; j++ )
{
if ( list[i] > list[j] )
{
tmp = list[i];
list[i] = list[j];
list[j] = tmp;
}
}
}
}
}


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};
SelectSorter sh=new SelectSorter();
sh.Sort(iArrary);
for(int m=0;m<iArrary.Length;m++)
Console.Write("{0} ",iArrary[m]);
Console.WriteLine();
Console.ReadLine();
}
}
}

chinaraul 2003-08-02
  • 打赏
  • 举报
回复
果然酷。能否再给一个选择排序的例子。
TheAres 2003-08-02
  • 打赏
  • 举报
回复
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();
Console.ReadLine();
}
}
}
saucer 2003-08-02
  • 打赏
  • 举报
回复
http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=256&lngWId=10

but you should be using
Array.Sort(YourArrayObject);

111,094

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧