c#中写个Swap方法来实现冒泡排序 看看哪里错了

2025-05-04 15:45:37
推荐回答(3个)
回答1:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Swap2
{
class Program
{
static void Main(string[] args)
{
double[] score = new double[5];
string scorestr="";
double[] cj=new double[5];

Console.WriteLine("输入5名成员的成绩:");
for (int i = 0; i < 5; i++)
{
Console.Write("第{0}位的成绩",i+1);
Console.WriteLine();
cxsr:
try
{
cj[i] = Convert.ToDouble(Console.ReadLine());
if (cj[i]>1500)
{
Console.WriteLine("你的输入的第{0}名成员成绩过于离谱请检查重新输入!",i+1);
goto cxsr;
}
}
catch (Exception ex)
{
Console.WriteLine("对不起您的输入第{1}名成员成绩引起{0}错误请重新输入该成员成绩。", ex.Message,i+1);
goto cxsr;
}

}

score= Swap(cj);
foreach(double it in score)
{
scorestr+=" "+it;
}

Console.WriteLine("输出排序后的成员:{0}", scorestr);
Console.ReadLine();
}

private static double[] Swap(double[] score)
{
for( int i=0;i {
for(int j=i;j {
if(score[i]>score[j])
{
double temp;
temp=score[j];
score[j]=score[i];
score[i]=temp;
}
}
}
return score;
}
}
}
帮你改写了一个。是C#控制台的。你可以看看。 你的那个我拿过去错误一大堆。改了半天。

回答2:

for (i = 0; i < 5; i++)
{ Console.WriteLine("输入5名成员的成绩:");
}
此处都没有输入数据,下面就开始调用swap()方法,肿么能排出来?
record=Swap(ref int[] score);

回答3:

调式下不就知道了