2016-12-01 42 views
-1
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

的错误是不言自明!改变你的返回类型 – Arash

+1

你不能返回'double []',因为方法的返回类型是'double'。修复方法签名中的错字。 – Abion47

+0

1)请发布可编译的例子,你缺少分号和括号。 2)请使用正确的拼写和语法。 3)你可能想要返回'sorted',而不是'testgrades'。 4)你正在对一个双精度数组进行排序,所以你应该返回一个'double []'的值,而不是简单的'double'。 – Quantic

回答

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 
相关问题