Can someone please tell me the order of this merge sort?
#include<iostream.h>
void merge(int[], int,int,int);
void merge_sort(int[],int);
int min(int x,int y)
{
if(x<=y)
return x;
else
return y;
}
void main()
{
int array[16] = {5,0,12,1,4,3,25,6,8,7,45,9,13,2,17,10};
int i;
cout<<"Unsorted : ";
for(i=0; i<16; i++)
{
cout<<array[i]<<" ";
}
cout<<endl<<endl;
merge_sort(array,16);
cout<<"Sorted : ";
for(i=0; i<16; i++)
{
cout<<array[i]<<" ";
}
cout<<endl<<endl;
}
void merge_sort(int a[],int n)
{
int i,j;
int from,mid,to;
for(i=2; i<=n; i *= 2)
{
for(j=0; j<n; j += i)
{
from = j;
to = min(j+i-1, n-1);
mid = (from + to)/2;
merge(a,from,mid,to);
}
}
if( n%(i/2) != 0 )
merge(a,0,(n-1-(n%(i/2))),n-1);
}
void merge(int a[],int low,int mid,int high)
{
int temp[16] = {0};
int l = low,h = high, m = mid+1;
int i,k;
i = l;
while((l<=mid) && (m<=h))
{
if(a[l]<=a[m])
{
temp[i] = a[l];
l++;
}
else
{
temp[i] = a[m];
m++;
}
i++;
}
if(mid>=l)
{
for(k=l; k<=mid; k++)
{
temp[i] = a[k];
i++;
}
}
else if(high>=m)
{
for(k=m; k<=high; k++)
{
temp[i] = a[k];
i++;
}
}
for( k=low; k<=high; k++)
{
a[k] = temp[k];
}
}