Class Sorter


  • public class Sorter
    extends Object
    Sorting handler used by higher-level logic.
    • Constructor Detail

      • Sorter

        public Sorter()
        A light constructor which initializes algo to a QuickSort object.
    • Method Detail

      • setStrategy

        public void setStrategy​(SortAlgorithm algorithm)
        Method for switching sorting algorithms.
        Parameters:
        algorithm - a SortAlgorithm object to assign to algo and be used from now on.
      • sort

        public boolean sort​(Cell[][] tab,
                            int column,
                            int maxIter,
                            SortAlgorithm.Order order)
        Wrapper to call SortAlgorithm.sort(Cell[][], int, int, Order) of the currently chosen SortAlgorithm. Allows using a single Sorter object to perform sorting with differnt algorithms
        Parameters:
        tab - a 2-D array of type Cell to be sorted.
        column - the index of the column which will be the sorting criteria.
        maxIter - maximum number of iterations. Value of -1 means unlimited iterations, <-1 means none.
        order - an enum Order value determining the sorting direction.
        Returns:
        a boolean value of whether sorting could be completed in the given number of iterations.
      • countingSort

        public static boolean countingSort​(int[] tab,
                                           SortAlgorithm.Order order)
        A simple implementation of the counting sort algorithm This implementation only works for 1-D arrays of integers.
        Parameters:
        tab - a 2-D array of type Cell to be sorted.
        order - an enum Order value determining the sorting direction.
        Returns:
        a boolean value of whether sorting could be completed in the given number of iterations.
        Throws:
        IllegalArgumentException - if given array contains negative values.