Generic version of merge sort algorithm

Rowley4
Rowley4 used Ask the Experts™
on
I need to implement a generic version of the merge sort algorithm

import java.util.Arrays;

public class MergeSortTester
{
   public static void main(String[] args)
   {
      String[] words = 
      {
         "Mary", "had", "a", "little", "lamb"
      };

      MergeSorter<String> sorter = new MergeSorter<String>(words);
      sorter.sort();
      System.out.println(Arrays.toString(words));      
      System.out.println("Expected: [Mary, a, had, lamb, little]");
   }
}

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
what is the question

Author

Commented:
I am not sure how to implement a generic version of the merge sort algorithm into this code.
Create a mergesort algorithm in MergeSorter.java that will sort anything you give it.
Basically if the type is <String> the algorithm will use a string comparator.
If it is numeric it will have a numeric comparator
if it is an object the object class must implement the Comparator interface.
Mick BarryJava Developer
Top Expert 2010
Commented:

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial