티스토리 뷰
버블 정렬 방법에서 사랑 점수가 같을 경우 스왑 할 작은 코드를 추가해야합니다.
for (int j = 0; j < n - i - 1; j++) {
if (a[j] > a[j + 1]) {
temp = a[j];
a[j] = a[j + 1];
a[j + 1] = temp;
// Sort them according to their name
temps = name[j];
name[j] = name[j + 1];
name[j + 1] = temps;
}else if(a[j] == a[j + 1]){
int result = name[j].compareTo(name[j + 1]);
if(result < 0){
temps = name[j];
name[j] = name[j + 1];
name[j + 1] = temps;
}
}
}
출처
https://stackoverflow.com/questions/39930021