java.lang.ObjectSorter
Class Sorter provides sorting methods on linear arrays of double. Methods sortSelection(), sortInsertion(), sortBubble() and sortMerge() sort the array that is passed as an argument to them. Class Sorter uses the private methods minLocationFrom() and swap() to facilitate the development of the sorting methods. It provides the public method merge() which merges two sorted arrays. It also provides a random number generator which fills an array and array printing methods.
Constructor Summary | |
Sorter()
|
Method Summary | |
static double[] |
clone(double[] original)
Creates an exact copy of an array. |
static double[] |
extract(double[] original,
int start,
int end)
Extracts a portion of an array. |
static void |
fillRandomData(double[] a)
Fills a linear array with radmon data in the range [0..1). |
static double[] |
merge(double[] a1,
double[] a2)
Merges two sorted arrays. |
static void |
printH(double[] a)
Prints the elements of an array, all at the same line. |
static void |
printV(double[] a)
Prints the elements of an array, each at a different line. |
static void |
sortBubble(double[] a)
Sorts an array in O(n^2) time by using the "Bubble-sort" method. |
static void |
sortInsertion(double[] a)
Sorts an array in O(n^2) time by using the "insertion-sort" method. |
static void |
sortMerge(double[] a)
Sorts an array in O(nlogn) time by using the "merge-sort" method. |
static void |
sortSelection(double[] a)
Sorts an array in O(n^2) time by using the "selection-sort" method. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public Sorter()
Method Detail |
public static double[] clone(double[] original)
public static double[] extract(double[] original, int start, int end)
start
- The index of the first element to be extracted.end
- The index of the last element to be extracted.
It holds that (start <= end).
public static void fillRandomData(double[] a)
a
- The array to be filled. It cannot be NULL.public static double[] merge(double[] a1, double[] a2)
a1
- The first of the two arrays to be merged. It must be sorted and cannot be NULL.a2
- The second of the two arrays to be merged. It must be sorted and cannot be NULL.
public static void printH(double[] a)
a
- The array of which the ellements are printed.public static void printV(double[] a)
a
- The array of which the ellements are printed.public static void sortBubble(double[] a)
a
- The array to be sorted. It cannot be NULL.public static void sortInsertion(double[] a)
a
- The array to be sorted. It cannot be NULL.public static void sortMerge(double[] a)
a
- The array to be sorted. It cannot be NULL.public static void sortSelection(double[] a)
a
- The array to be sorted. It cannot be NULL.