Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public HashNode<String,V>[] sort(HashNode<String, V>[]arr){
- ArrayList<HashNode<String,V>> hashList = new ArrayList<HashNode<String,V>>(Arrays.asList(arr));
- for(int i = 0; i<arr.length; i++){
- arr[i] = hashList.get(i);
- }
- return (HashNode<String,V>[])MSDHelper(hashList, 0).toArray();
- }
- public ArrayList<HashNode<String, V>> MSDHelper(ArrayList<HashNode<String,V>> arr, int curPlace){
- ArrayList<HashNode<String, V>>[] array = (ArrayList<HashNode<String, V>>[])new ArrayList[129];
- //Initialize each value in the array.
- for(int i = 0; i<array.length; i++){
- array[i] = new ArrayList<HashNode<String, V>>();
- }
- //Loop through the array and put the values that are less than the curPlace in the 0th index and values bigger than curPlace into the next available index.
- for(int k = 0; k<arr.size(); k++){
- if(arr.get(k).getKey().length() <= curPlace){
- array[0].add(arr.get(k));
- }
- else {
- array[arr.get(k).getKey().charAt(curPlace+1)].add(arr.get(k));
- }
- }
- //Loop through the array to recursively sort the elements in the bucket.
- for (int j = 0; j < array.length; j++) {
- if (array[j].size() > 1){
- array[j] = MSDHelper(array[j], curPlace + 1);
- }
- }
- //Merge it all back together.
- for (int j = 1; j < array.length; j++) {
- array[0].addAll(array[j]);
- }
- return array[0];
- }
Add Comment
Please, Sign In to add comment