using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace 冒泡_排序
{
class Program
{
static void Main(string[] args)
{
int[] arr = { 1, 4, 5, 8, 9, 6, 5, 3, 2, 4, 4 };
BubbleSort(arr);
PrintArr(arr);
}
static void PrintArr(int[] arr)
{
for (int i = 0; i < arr.Length; i++)
{
Console.Write(arr[i]+" ");
}
}
static void BubbleSort(int[] arr)
{
//比较 的趟数
for (int i = 0; i < arr.Length; i++)
{
// 每一趟要比较 的次数
for (int j = 0; j < arr.Length - 1 - i; j++)
{
if (arr[j] < arr[j + 1])
{
int temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}
}
}
}
C#冒泡排序
最新推荐文章于 2024-07-13 08:57:13 发布