private void sort( List<Double> valueList,List<String> nameList) {
List<Double> xValue = new ArrayList<>();
List<String> xName = new ArrayList<>();
int de;
int i = 0;
Iterator<Double> it = valueList.iterator();
while(it.hasNext()){
de = 0;
for(int j = 0; j < valueList.size(); j ++) {
if(valueList.get(de) < valueList.get(j)) {
de = j;
}
}
xValue.add(i,valueList.get(de));
valueList.remove(de);
xName.add(i,nameList.get(de));
nameList.remove(de);
i++;
}
valueList = xValue;
nameList = xName;
}
直观的:
public static void main(String []fsdsf) {
List<Double> yValue = new ArrayList<>();
List<String> yName = new ArrayList<>();
yValue.add(9.0);
yName.add("aa");
yValue.add(12.0);
yName.add("bb");
yValue.add(3.0);
yName.add("cc");
yValue.add(7.0);
yName.add("dd");
List<Double> xValue = new ArrayList<>();
List<String> xName = new ArrayList<>();
int de;
int i = 0;
Iterator<Double> it = yValue.iterator();
while(it.hasNext()){
de = 0;
for(int j = 0; j < yValue.size(); j ++) {
if(yValue.get(de) < yValue.get(j)) {
de = j;
}
}
xValue.add(i,yValue.get(de));
yValue.remove(de);
xName.add(i,yName.get(de));
yName.remove(de);
i++;
}
for (Double d : xValue ) {
System.out.println(d);
}
for (String d : xName ) {
System.out.println(d);
}
}
排序前后: