Package edu.rit.util

Class Sorting.Object<T>

java.lang.Object
edu.rit.util.Sorting.Object<T>
Type Parameters:
T - Data type of the array elements.
Enclosing class:
Sorting

public abstract static class Sorting.Object<T> extends Object
Class Sorting.Object is the abstract base class for a helper object used to sort an array of objects of type T[].
Version:
20-Oct-2010
Author:
Alan Kaminsky
  • Constructor Details

    • Object

      public Object()
  • Method Details

    • comesBefore

      public abstract boolean comesBefore(T[] x, int a, int b)
      Compare two elements in the given array. This determines the order of the elements in the sorted array.
      Parameters:
      x - Array being sorted.
      a - Index of first array element being compared.
      b - Index of second array element being compared.
      Returns:
      True if x[a] comes before x[b] in the desired ordering, false otherwise.
    • swap

      public void swap(T[] x, int a, int b)
      Swap two elements in the given array.

      The default implementation swaps x[a] with x[b]. A subclass can override this method to do something different; for example, to swap the elements of other arrays in addition to x.

      Parameters:
      x - Array being sorted.
      a - Index of first array element being swapped.
      b - Index of second array element being swapped.