Need help in Designing and implementing bucket-sort algorithm
I want to design and implement a version of the bucket-sort algorithm for sorting a linked list of n entries (for instance, a list of type java.util.LinkedList) with integer keys taken from the range [0,N-1], for N >= 2. The algorithm should run in O(n+N) time.
-------------------------------------------------------------
Following is what I need to do....
a.) Import the attached archive file into an eclipse project. Follow the attached starter files (write a static method that takes a LinkedList and integer as parameters.) I also have to catch that if keys are invalid, an exception is thrown.
b.) Sorting a LinkedList of object/key pairs is worth 100%. I need to do that in one method with 2 loops.
c.) Sorting a LinkedList of Entries parameterized with generic types is worth 120%
bucketSort.java
Code:
/** Fill in bucketSort and entry.java for 100%
* OR
* Fill in bucketSortGeneric and genericEntry.java for 120%
*/
import java.util.LinkedList;
// import java.util.ArrayList;
class sortMethods {
public static void bucketSort(LinkedList<entry> List, int maxKey) throws IllegalKeyException {
}
public static <U extends genericEntry> void bucketSortGeneric(LinkedList<U> List, int maxKey)
throws IllegalKeyException {
}
}
entry.java
Code:
class entry {
public entry(int k, Object val) {
}
public int getKey() {
return 0;
}
public Object getVal() {
return null;
}
}
genericEntry.java
Code:
class genericEntry<K extends Number, V> {
public genericEntry(K nKey, V nVal) {
}
public K getKey() {
return null;
}
public V getVal() {
return null;
}
}
IllegalKeyException.java
Code:
public class IllegalKeyException extends Exception {
public IllegalKeyException() {
super();
}
public IllegalKeyException(String errorMessage) {
super(errorMessage);
}
}
Help would be greatly appreciated. THANKS!!!!