























using System;
namespace ConsoleApplication1
{
/// <summary>
/// Class1 的摘要说明。
/// </summary>
class Class1
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main(string[] args)
{
//
// TODO: 在此处添加代码以启动应用程序
//
aa();
}
public static void aa()
{
int[] r = new int[] {3,4,7,6,2,9};
bubblesort(ref r);
for(int i = 0; i < r.Length; i ++)
Console.Write(r[i]);
}
public static void bubblesort(ref int[] r)
{
int i,j,temp; //交换标志
bool exchange;
for(i=0; i<r.Length; i++) //最多做r.length-1趟排序
{
exchange=false; //本趟排序开始前,交换标志应为假
for(j=r.Length-2; j>=i; j--)
{
if(r[j+1]<r[j]) ////交换条件
{
temp=r[j+1];
r[j+1]=r[j];
r[j]=temp;
exchange=true; //发生了交换,故将交换标志置为真
}
}
if(!exchange) //本趟排序未发生交换,提前终止算法
{
break;
}
}
}
}
}
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。