|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.mhhe.clrs2e.RadixSort
Sorts an array of NonNegativeInteger
via the radix sort
algorithm from page 172 of Introduction to Algorithms,
Second edition.
Nested Class Summary | |
private static class |
RadixSort.RadixKeyExtractor
Interface that allows us to pull out the sort key from an object. |
Field Summary | |
private int |
digits
How many digits per key. |
private int |
NO_DIGITS
Indicates that the number of digits was not set. |
private int |
NO_RADIX
Indicates that no radix was set. |
private int |
radix
The radix being used. |
Constructor Summary | |
RadixSort()
Initializes the instance variables to default nonsense values. |
|
RadixSort(int radix)
Initializes the radix instance variables to its
argument and and digits to a default value. |
|
RadixSort(int radix,
int digits)
Initializes the instance variables to its arguments. |
Method Summary | |
private static int |
calculateDigits(int radix,
int max)
Determines how many digits of a given radix are necessary. |
void |
radixSort(com.mhhe.clrs2e.NonNegativeInteger[] array,
int radix)
Implements radix sort, calculating the number of digits to sort. |
void |
radixSort(com.mhhe.clrs2e.NonNegativeInteger[] array,
int r,
int d)
Implements radix sort. |
void |
sort(com.mhhe.clrs2e.NonNegativeInteger[] array)
Sorts an array of NonNegativeInteger . |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
private final int NO_RADIX
private final int NO_DIGITS
private int radix
private int digits
Constructor Detail |
public RadixSort()
public RadixSort(int radix)
radix
instance variables to its
argument and and digits
to a default value.
radix
- Value to use for the radix.public RadixSort(int radix, int digits)
radix
- Value to use for the radix.digits
- Number of digits to use.Method Detail |
private static int calculateDigits(int radix, int max)
radix
- The radix.max
- Maximum value of any key.
public void sort(com.mhhe.clrs2e.NonNegativeInteger[] array)
NonNegativeInteger
. Wrapper for
radixSort
. Calculates the optimal radix if the
radix
instance variable has not been set.
array
- The array of NonNegativeInteger
to be
sorted.public void radixSort(com.mhhe.clrs2e.NonNegativeInteger[] array, int radix)
array
- The array of NonNegativeInteger
to be
sorted.radix
- The radix to use.public void radixSort(com.mhhe.clrs2e.NonNegativeInteger[] array, int r, int d)
array
- The array of NonNegativeInteger
to be
sorted.r
- The radix to use.d
- The number of digits to use.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |