這可能是一個相當簡單的問題。我只是無法弄清楚如何按降序而不是升序進行排序。誰能幫我嗎?如何讓這種合併排序按降序而不是按升序排列?
public static void sortYear(Movie4[] movies, int low, int high)
{
if (low == high)
return;
int mid = (low + high)/2;
sortYear(movies, low, mid);
sortYear(movies, mid + 1, high);
mergeYears(movies, low, mid, high);
}
public static void mergeYears(Movie4[] movies, int low, int mid, int high)
{
Movie4[] temp = new Movie4[ high - low + 1 ];
int i = low, j = mid + 1, n = 0;
while (i <= mid || j <= high)
{
if (i > mid)
{
temp[ n ] = movies[ j ];
j++;
}
else if (j > high)
{
temp[ n ] = movies[ i ];
i++;
}
else if (movies[ i ].getYear() < movies[ j ].getYear())
{
temp[n] = movies[i];
i++;
}
else
{
temp[n] = movies[j];
j++;
}
n++;
}
for (int k = low ; k <= high ; k++)
{
movies[ k ] = temp[ k - low ];
}
}
是的,他是這麼說的......就在這個問題結束...... – acdcjunior
這是家庭作業,但它不是全部問題。我必須使用降序合併排序編寫程序,但我無法弄清楚。看這個沒什麼問題。 – user1914491
'「,所以我只是打算繼續打字」 - 是的,你不應該這樣做。 – Dukeling