Я вот не знаю, может добавить else после if. Но имеет ли это смысл? Подскажите пожалуйста. Спасибо!
public static <T extends Comparable<T> > void bubbleSort(List<T> theList) {
int lastToConsider = theList.size(); // pass size of the list to the variable
while (lastToConsider > 1) { // while the last element will not reached, while loop condition is true
for (int j = 0; j < lastToConsider - 1; j++) {
if (theList.get(j).compareTo(theList.get(j+1)) > 0) { // if last element larger than next element swap them
swap(theList,j,j+1);
}
}
lastToConsider--; // decrement variable to move through elements in while loop
}
}