您的位置:首页 > 其它

冒泡排序大比拼---看看谁的算法最简单

2009-12-23 14:13 260 查看
一.

///////////////////////////////////////////////////////////////////////////////

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

namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{

int[] a = { 3, 4, 7, 10, 5, 9 };
int[] b = BubbleSort(a);
for (int i = 0; i < b.Length; i++)
{
Console.Write(b[i].ToString() + " ");

}
Console.ReadLine();
}

public static int[] BubbleSort(int[] list)
{
int i, temp;
for (int j = 0; j < list.Length; j++)
{
for (i = list.Length - 1; i > j; i--)
{
if (list[j] < list[i])
{
temp = list[j];
list[j] = list[i];
list[i] = temp;
}
}
}

return list;
}
}
}

二.

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////

static void Main(string[] args)
{

int[] a = { 3, 4, 7, 10, 5, 9 };
Array.Sort(a);
for (int i = 0; i < b.Length; i++)
{
Console.Write(b[i].ToString() + " ");

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