Package edu.rit.util
Class Sorting.Short
java.lang.Object
edu.rit.util.Sorting.Short
- Enclosing class:
Sorting
Class Sorting.Short is the base class for a helper object used to sort an
array of type
short[]
.- Version:
- 20-Oct-2010
- Author:
- Alan Kaminsky
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
comesBefore
(short[] x, int a, int b) Compare two elements in the given array.void
swap
(short[] x, int a, int b) Swap two elements in the given array.
-
Constructor Details
-
Short
public Short()
-
-
Method Details
-
comesBefore
public boolean comesBefore(short[] x, int a, int b) Compare two elements in the given array. This determines the order of the elements in the sorted array.The default implementation returns true if
x[a] < x[b]
, which sorts the array into ascending order. A subclass can override this method to obtain a different ordering criterion; for example, descending order.- 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 beforex[b]
in the desired ordering, false otherwise.
-
swap
public void swap(short[] x, int a, int b) Swap two elements in the given array.The default implementation swaps
x[a]
withx[b]
. A subclass can override this method to do something different; for example, to swap the elements of other arrays in addition tox
.- Parameters:
x
- Array being sorted.a
- Index of first array element being swapped.b
- Index of second array element being swapped.
-