2

Below is my implementation for merge sort algorithm

private void mergeSort(Integer[] t,int low, int high)
{
    if(low<high)
    {
        int mid=(low+high)/2;
        mergeSort(t,low,mid);
        mergeSort(t,mid+1,high);

        merge(t,low,mid,high);
    }
}

private void merge(Integer[] t, int low, int mid, int high){
    Integer[] temp = t.clone();
    int i=low,j=mid+1,k=low;
    while(i<=mid && j<=high)
    {
        temp[k++] = t[i] < t[j] ? t[i++] : t[j++];
    }
    while(i<=mid)
        temp[k++] = t[i];
    while(j<=high)
        temp[k++] = t[j];

    System.out.println(Arrays.toString(temp));

 }

I was considering if i could modify it to pure functional style like using java 8. Somewhere close to what how we do in Scala.

Android Mason
  • 459
  • 1
  • 6
  • 17

0 Answers0