您的位置:首页 > 其它

冒泡排序

2013-12-17 10:26 323 查看
一觉醒来,没事干,写个冒泡醒醒睡意!

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

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int[] arrs = { 1, 3, 5, 4, 2, 3, 5, 3, 5, 6, 8, 9, 2, 10 };
Srot(arrs);
foreach (int item in arrs)
{
Console.WriteLine(item);
}

Console.ReadKey();
}

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

return arr;

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