C#的冒泡排序法代码这段有错误,请问错在哪?谢谢

来源:百度知道 编辑:UC知道 时间:2024/07/07 10:08:40
using System;
using System.Collections.Generic;
using System.Text;

namespace test2
{
class Program
{
public void MaoPaoPaiXu(int[] arr)
{
int i, j, temp=0;
for (i = 0; i < arr.Length - 1; i++)
{
for (j = 0; j < arr.Length - i - 1; j++)
{
if (arr[j] > arr[j + 1])
temp = arr[i];
arr[i] = arr[j + 1];
arr[j + 1] = temp;

}

}
for (i = 0; i < arr.Length; i++)
{
Console.Write(arr[i] + "\t");
}
Console.ReadLine();
}
static void Main(string[] args)
{
int[] array = new int[] {20,18,16,14,9,10,5};

public void MaoPaoPaiXu(int[] arr)
{
int i, j, temp = 0;
for (i = 0; i < arr.Length - 1; i++)
{
for (j = 0; j < arr.Length - 1; j++)
{
if (arr[j] > arr[j + 1])
{
temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}

}
for (i = 0; i < arr.Length; i++)
{
Console.Write(arr[i] + "\t");
}
Console.ReadLine();
}
static void Main(string[] args)
{
int[] array = new int[] { 20, 18, 16, 14, 9, 10, 5 };
Program p = new Program();
p.MaoPaoPaiXu(array);

}

for(