你的位置:首页 > ASP.net教程

[ASP.net教程]C#冒泡排序法程序代码


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication6
{
class Program
{
static void Main(string[] args)
{
int[] num = new int[] { 19, 12, 34, 45, 65, 12, 33, 432 };

for (int i = 0; i < num.Length - 1; i++)
{
for (int j = 0; j < num.Length - 1 - i; j++)
{
if (num[j] > num[j + 1])
{
int a = num[j];
num[j] = num[j + 1];
num[j + 1] = a;
}
}
}
foreach (int number in num)
{
Console.Write(number+" ");
}
Console.ReadLine();
}
}
}