111,125
社区成员
发帖
与我相关
我的任务
分享 class Program
{
static void Main(string[] args)
{
int[] a = { 2, 6, 4, 8, 10, 12, 89, 68, 45, 37 };
string output = "The original order is : ";
for (int i = 0; i < a.Length; i++)
output += a[i] + " ";
Console.WriteLine(output += "\n");
BubbleSort(a);
output = "The new order is : ";
for (int i = 0; i < a.Length; i++)
output += a[i] + " ";
Console.WriteLine(output);
}
static void BubbleSort(int[] b)
{
for (int pass = 1; pass < b.Length; pass++)
for (int i = 0; i < b.Length - 1; i++)
if (b[i] > b[i + 1])
Swap(b, i);
}
static void Swap (int[] c, int d)
{
int hold;
hold = c[d];
c[d] = c[d + 1];
c[d + 1] = hold;
}
}
现在了解啦