UNB/ CS/ David Bremner/ teaching/ old/ cs1083/ java/ ArrayMerger.java
import java.util.Random;

public class ArrayMerger<T extends Comparable<T>> {

    public void merge(T [] a, T[] b, T[] c) {

        int i=0, j=0;

        while (i + j < a.length + b.length) {
            T next;
            if (i >= a.length)
                next=b[j++];
            else if (j >= b.length)
                next=a[i++];
            else
                if (a[i].compareTo(b[j]) <= 0)
                    next=a[i++];
                else
                    next=b[j++];
            c[i+j-1]=next;
        }
    }

    public static void main(String [] args){

        String[] names1 = {"Harry", "Tom", "Moe", "Curly"};
        String[] names2 = {"Bob", "Alice", "Mallory"};

        SelectionSort<String> sorter=new SelectionSort<String>();
        sorter.sort(names1);
        sorter.sort(names2);

        String[] names3 = new String[names1.length+names2.length];
        ArrayMerger<String> merger = new ArrayMerger<String>();

        merger.merge(names1,names2, names3);

        for (String name : names3) {
            System.out.println(name);
        }
    }



}