using System;
class ArraySort
{
public static void Main()
{
int[] d = {10,15,21,43,17,98,2,74,63,10};
int temp;
//冒泡法排序
for(int i=0; i<d.Length; i++)
for(int j=i+1; j<d.Length; j++)
if(d[i]<d[j])
{
temp = d[i];
d[i]=d[j];
d[j]=temp;
}
//输出排序结果
foreach(int i in d)
Console.Write("{0}, ", i);
}
}
博客展示了一段C#代码,定义了一个ArraySort类,在Main方法中创建整数数组,使用冒泡法对数组进行排序,最后输出排序结果,体现了冒泡排序算法在C#中的实现。

1万+

被折叠的 条评论
为什么被折叠?



