S7200冒泡排序

子程序







主程序


预设数据


执行结果


实际实现的原理(C#)

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading;

namespace ConsoleApplication1

{

class
Program

{

static
void Main(string[] args)

{

float[] a = new
float[10]{12.0F,100.0F,67.0F,77.0F,54.0F,55.0F,99.0F,789.0F,123.0F,6789.0F};

for (int i=1; i <=9;++i )

{

for (int j=0; j <= 9 – i;++j )

{

if(a[j]>=a[j+1])

{

var tmp = a[j];

a[j] = a[j + 1];

a[j + 1] = tmp;

}

}

}

//打印结果

foreach (float i in a)

{

Console.WriteLine(i.ToString(“0.0”));

}

}

}

}

执行结果

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注