import java.util.List; import java.util.Comparator; import static java.util.Collections.swap; public class Sort { public static void selection(List list, Comparator comparator) { int i, j, m, n = list.size(); for (i = 0; i < n; ++i) { for (m = j = i; j < n; ++j) if (comparator.compare(list.get(j), list.get(m)) < 0) m = j; swap(list, i, m); } } public static > void selection(List list) { selection(list, new Compare()); } public static void bubble(List list, Comparator comparator) { for (int n = list.size(), m = 0; n > 1; n = m, m = 0) for (int i = 1; i < n; ++i) if (comparator.compare(list.get(i), list.get(i - 1)) < 0) swap(list, m = i, i - 1); } public static > void bubble(List list) { bubble(list, new Compare()); } public static void heap(List list, Comparator comparator) { var heap = new Heap(list, comparator); for (int i = 1; i < list.size(); ++i) heap.pop(); } public static > void heap(List list) { heap(list, new Compare()); } }