17 Clean implementations of Java Sorting Algorithms

Well, in this post I will share with you 17 Java Sorting implementations I had to code in an algorithms course at college! The package includes the following implementations (from the easiest to the more complex ones).

  • Bubble Sort (SorterType.BUBBLE)
  • Selection Sort (SorterType.SELECTION)
  • Insertion Sort (SorterType.INSERTION)
  • HSort (SorterType.H)
  • Shell Sort (SorterType.SHELL)
  • Quick Sort (SorterType.QUICK)
  • Quick “Cut” Sort (SorterType.QUICK_CUT)
  • Quick “Median of Three” Sort (SorterType.QUICKMEDOF_THREE)
  • Quick “Non recursive” Sort (SorterType.QUICKNONRECURSIVE)
  • Quick “Three way Partition” Sort (SorterType.QUICKTHREEPARTITION)
  • Bottom-Up Merge Sort (SorterType.MERGEBOTTOMUP)
  • Bottom-Up Linked-List Merge Sort
  • Top-Down Merge Sort (SorterType.MERGE)
  • Top-Down Linked-List Merge Sort
  • Binary Heap Sort(SorterType.HEAP_BINARY)
  • Ternary Heap Sort (SorterType.HEAP_TERNARY)

All implementations come with a brief explanation for you to understand how they work.


All Sorting implementations extends AbstractSorter which implements Sorter. The Sorter interface is generified. This allows subsequent implementations to be capable to sort any collection of objects as long as exists a Comparator for that Type of objects.

public interface Sorter {
  <T> void sort(Comparator<T> comparator, List<T> list) ;

  SorterType getType();

Continue Reading →