public class Mergesort {
private int[] numbers;
private int[] helper;
private int number;
public void sort(int[] values) {
this.numbers = values;
number = values.length;
this.helper = new int[number];
mergesort(0, number - 1);
}
private void mergesort(int low, int high) {
// check if low is smaller than high, if not then the array is sorted
if (low < high) {
// Get the index of the element which is in the middle
int middle = low + (high - low)/2;
// Sort the left side of the array
mergesort(low, middle);
// Sort the right side of the array
mergesort(middle + 1, high);
// Combine them both
merge(low, middle, high);
}
}
}
数字と文字の配列を並べ替えるためにこのコードを実装していますが、これは私が知る限り、このコードが終了するまでです番号のみをソートする。どのように私はそれをフレームとチャーマーの混合を並べ替えるには?マージソートで文字と数字の混合をソートする
混在したものを並べ替えることはできません。何か共通点があります。あなたの質問にもっと詳しく教えてください。int配列とchar配列の両方を並べ替えるソートメソッドが必要ですか? – A4L
上記の点を明確にするには、「a」または「1」の値が大きくなります。 – kabanus
はい、それはまさに私が意味するものです。私はint型とchar型の両方の配列を並べ替えることができるメソッドを必要とします。選択またはマージソートのいずれかを使用します – Dave