private static <E> void merge(E[] array, E[] temp,int begin, int end, Comparator<E> comparator){

        int i = begin;
        int tracker = begin;
        int middex = (begin+end)/2;
        int rightstart = middex+1;
        
        // Goes through and compares the two segments of the array that we are focusing on.
        while(i <= middex && rightstart <= end){
        	if(comparator.compare(array[i], array[rightstart])<=0){
        		temp[tracker++] = array[i++];
        	}else{
        		temp[tracker++] = array[rightstart++];
       		}
       	}
     
       	while(i <= middex){ //Means right completed first so shifts all into temp
       		temp[tracker++] = array[i++];
       	}
       	
       	//Number of elements in temp array that need to be put into array.
       	int elements = tracker -begin;
       	for(int j =0; j < elements; j++){
       		array[begin+j] = temp[begin+j];
       	}
    }