返回已排序的数组以在main方法中打印

时间:2016-12-01 17:55:50

标签: c#

    public static double bubblesort( double [] testgrades, int grades)
    {
        double[] sorted = new double[grades];
        for (int i = 0; i < testgrades.Length; i++)
        {
            for (int j = 1; j < testgrades.Length - 1; j++)
            {
                if (testgrades[j] > testgrades[j + 1])
                {
                    double tmp = testgrades[j];
                    testgrades[j] = testgrades[j + 1];
                    testgrades[j + 1] = tmp;


                }
                return testgrades

错误说can return type double[] to double。 还说没有返回值,也没有让我使用名称冒泡排序新方法

1 个答案:

答案 0 :(得分:0)

你必须选择:

public static void bubblesort(ref double [] testgrades, int grades)
 . ...
   //  return testgrades <-- don't return anything, testgrades it's already sorted

或:

public static double[] bubblesort(ref double [] testgrades, int grades)
//... everything else remains the same, just change the signature