本帖最后由 黑色L 于 2013-10-2 12:57 编辑
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace _34冒泡排序
{
class Program
{
static void Main(string[] args)
{
int[] array = { 1, 2, 3, 4, 5 };
//打印初始数组
Console.Write("\n初始数组\n");
for (int i = 0; i < array.Length; i++)
{
Console.Write(array + " ");
}
Console.WriteLine();
//冒泡排序
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 = array[j + 1];
array[j + 1] = temp;
}
}
}
//打印排序数组
Console.Write("\n排序数组\n");
for (int i = 0; i < array.Length; i++)
{
Console.Write(array + " ");
}
Console.ReadKey();
}
}
}
|
|