I\'m running an example to understand the behavior of Comparator in Java.
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparat
Sorting algorithms are a complex topic. Consider this very simple (but inefficient) algorithm.
Compare the first item to the second item. Keep track of the higher item and compare it to the next item. Keeping track of the highest item until the get to the end of the list to find the highest item in the list. Place highest one in a new list, and remove it from the original list.
Then repeat the previous steps until the original list is empty.
Because you are going through the list multiple times, you could end up comparing an item its neighbor multiple times. Perhaps even consecutively on different passes.