冒泡排序代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _05冒泡排序
{
class Program
{
static void Main(string[] args)
{
//冒泡排序算法:
//大数往上冒,小数往下沉
//对于一组数进行按照从大到小或者从小到大的一个顺序排列算法
int[] array = { 23, 30, 28, 40, 21 };
for (int i = 0; i < array.Length - 1;i++ )
{
for (int j = 0; j < array.Length - 1 - i;j++ )
{
if(array[j]<array[j+1])
{
int temp=array[j];
array[j]=array[j+1];
array[j + 1] = temp;
}
}
}
for (int i = 0; i < array.Length;i++ )
{
Console.Write(array[i]+">");
}
Console.ReadLine();
}
}
}