My code:
public class MyBubbleSort {
public static void bubble_srt(List<Integer> score, List<String> name, List<Integer> pic) {
int n = score.size();
int k;
for (int m = n; m >= 0; m--) {
for (int i = 0; i < n - 1; i++) {
k = i + 1;
if (score.get(i) < score.get(k)) {
swapNumbers(i, k, score, name, pic);
}
}
printNumbers(score);
}
}
private static void swapNumbers(int i, int j, List<Integer> score, List<String> name, List<Integer> pic) {
int temp;
temp = score.get(i);
score.set(i, score.get(j));
score.set(j, temp);
String s;
s = name.get(i);
name.set(i, name.get(j));
name.set(j, s);
int p;
p = pic.get(i);
pic.set(i, pic.get(j));
pic.set(j, p);
}
private static void printNumbers(List<Integer> input) {
for (int i = 0; i < input.size(); i++) {
System.out.print(input.get(i) + ", ");
}
System.out.print("\n");
}
}
Anonymous User
15-Dec-2015