Generic version of merge sort algorithm

Rowley4 used Ask the Experts™
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);
      System.out.println("Expected: [Mary, a, had, lamb, little]");

Open in new window

Watch Question

Do more with

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


I am not sure how to implement a generic version of the merge sort algorithm into this code.
Create a mergesort algorithm in 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

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