A sort is stable if elements that compare as equal keep their original relative order. This matters as soon as records are sorted by one field: sorting competitors by score should keep, among equal scores, the order in which they registered.
Write StableMerge with two generic sorts taking a Comparator:
public static <E> void mergeSort(E[] list, Comparator<? super E> order)
public static <E> void selectionSort(E[] list, Comparator<? super E> order)
Read n, then n lines name score. Sort two copies by score, highest first, one with each algorithm; print both results and whether each kept the equal scores in arrival order. For the input
6
Ana 90
Ben 85
Cai 90
Dee 70
Eli 85
Fay 90
the program prints
Merge sort: [Ana 90, Cai 90, Fay 90, Ben 85, Eli 85, Dee 70]
Selection sort: [Ana 90, Cai 90, Fay 90, Eli 85, Ben 85, Dee 70]
Merge sort kept equal scores in their arrival order: true
Selection sort kept equal scores in their arrival order: false