Class SortUtil

java.lang.Object
com.mckoi.util.SortUtil

public final class SortUtil extends Object
Provides various sort utilities for a list of objects that implement Comparable. It also provide some methods that can be used on a sorted list of objects, such as a fast search method.

All the methods in this class are static.

Author:
Tobias Downer
  • Constructor Details

    • SortUtil

      public SortUtil()
  • Method Details

    • quickSort

      public static void quickSort(Comparable[] list, int min, int max)
      Performs a quick sort on the given array of Comparable objects between the min and maximum range. It changes the array to the new sorted order.
    • quickSort

      public static void quickSort(Comparable[] obs)
      Performs a quick sort on the given array of Comparable objects. It changes the array to the new sorted order.
    • sortedIndexOf

      public static int sortedIndexOf(Comparable[] list, Comparable val, int lower, int higher)
      Quickly finds the index of the given object in the list. If the object can not be found, it returns the point where the element should be added.
    • sortedQuickFind

      public static SearchResults sortedQuickFind(Comparable[] list, Comparable val, SearchResults results)
      Quickly finds the given element in the array of objects. It assumes the object given is of the same type as the array. It returns null if the given object is not in the array. If the object is in the array, it returns a SearchResults object that contains information about the index of the found object, and the number of objects like this in the array. Not that it takes a 'SearchResults' object to store the results in. This is for reuse of an old SearchResults object that is no longer needed. This prevents gc and overhead of having to allocate a new SearchResults object. This method works by dividing the search space in half and iterating in the half with the given object in.