您的位置:首页 > 编程语言 > C#

C#数组冒泡排序

2016-03-25 16:55 477 查看
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
public static void Pop(int n,int []x)
{
for (int i = 0; i < n-1; ++i)
{
for (int j = 0; j < n - i - 1; ++j)
{
if (x[j] > x[j+1])
{
int a = x[j];
x[j] = x[j+1];
x[j+1] = a;
}
}
}
}

static void Main(string[] args)
{
int []a={2,3,8,9,4,6,7,1,0,5};
Pop(10, a);
foreach (int  item in a)
{
Console.WriteLine(item);
}
Console.ReadKey();
}
}
}


运行结果:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: