这可能是一个相当简单的问题。我只是不知道如何按降序而不是升序进行排序。谁能帮我吗?
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 ];
}
}