Would I just rewrite this twice over or is there a more efficient way I can go about doing this? How can I get items to sort in the same pattern(low to high) as price?
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;
}
}
}
}