csharp冒泡排序
时间: 2023-12-14 17:34:53 浏览: 76
以下是C#中的冒泡排序示例代码:
```csharp
using System;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
int[] arr = new int[] { 64, 57, 25, 46, 95, 12, 35, 47, 55 };
int temp = 0;
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;
}
}
}
Console.WriteLine("排序后的数组为:");
for (int i = 0; i < arr.Length; i++)
{
Console.Write(arr[i] + " ");
}
}
}
}
```
阅读全文