Sunday, July 2, 2017

mergesort

void mergesort( int arr[], int len)
{
  int low, mid, high, last;
  for(int i =2; i<len; i*=2){
    low =0; high =i-1;
    mid = (low+high)/2;
    while(high<len){
      merge(arr,low, mid, high);
      low += i;
      high += i;
      mid = (low+high)/2;
    }
    if( high != len-1){
    low -= i;
    mid = high-i;
    high = len-1;
    merge(arr, low, mid, high);
    }
  }

}

No comments:

Post a Comment