2016-12-01 18 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) 'testgrades'ではなく、' sorted'を返すことをお勧めします。 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 
関連する問題