0
我需要通过其标题以简单的方式对书对象进行排序。然而,我写的选择排序算法不能正常工作,只是移动书本,但没有明显的顺序。我究竟做错了什么?按字母顺序排列数组
int j;
int b;
for (int i = 0; i < 20 - 1; i++) {
int minIndex = i;
for (j = i + 1; j < 20; j++) {
b = (bookA[j].getTitle().compareTo(bookA[minIndex].getTitle()));
if (b < 0) {
minIndex=j;
}
}
Book temp = bookA[i];
bookA[i] = bookA[j];
bookA[j] = temp;
}
for (int z = 0; z < 20; z++)
System.out.println(bookA[z].toString());