-1
これを2回以上書き直すのですか、それとももっと効率的な方法がありますか? これについてはどうなりますか?価格と同じパターン(低から高)でソートするアイテムを取得するにはどうすればよいですか?2つの配列を同時に(選択ソートを使用して)ソートするにはどうすればよいですか? JAVA
public class W14_3 {
public static void main(String [] args){
double[] price={73.25, 48.0, 345.0, 152.35, 196.50};
String[] items={"bag", "stationary", "books", "shoes","clothing"};
selectionSort(price , items);
for(int i = 0; i<price.length; i++)
System.out.println(price[i]);
for(int j=0; j<items.length; j++){
System.out.println(items[j]);
}
}
public static void selectionSort(double[] P , String[] I){
for(int startIndex=0; startIndex <P.length-1; startIndex++)
{
double min = P[startIndex];
int indexOfMin = startIndex;
for(int j= startIndex +1; j< P.length; j++)
if(P[j] < min)
{
min =P[j];
indexOfMin=j;
}
P[indexOfMin] = P[startIndex];
P[startIndex] = min;
}
}
}
}
個別の配列には物を持ってはいけません。アイテムを保持するクラスとそれに対応する価格を作成し、その配列を1つだけ持ちます。 –