using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Test
{
class Program
{
static void Main(string[] args)
{
Sorts sorts = new Sorts();
int[] array = { 9, 6, 4, 5, 3 };
sorts.SortMethon(array);
foreach (int i in array)
{
Console.Write("{0} ", i);
}
Console.WriteLine();
Console.ReadKey();
}
public class Sorts
{
public void SortMethon(int[] array)
{
int length = array.Length;
for (int i = 0; i <= length - 2; i++)
{
for (int j = length - 1; j >= 1; j--)
{
// 冒泡排序
if (array[j] < array[j - 1])
{
int temp = array[j];
array[j] = array[j - 1];
array[j - 1] = temp;
}
}
}
}
}
}
}
输出截图: