void rotate_r(int *arr,int start,int end)//working/remember that arr[i1] hold original value
//rotate array right
{
int k;
for(k=0;k<=(end-start);k++) arr[end-k+1]=arr[end-k];
}
void merge(int * arr, uint p, uint q, uint r)
//merge ip,first function
{
int tmp=0;
while((q+1) <= r && p <= q)
{
if(arr[p]>=arr[q+1]) //rotating and replecment segment
{
tmp=arr[q+1];
rotate_r(arr,p,q);
arr[p]=tmp;
p++; q++;
}
else p++;
}
}
void mergesort(int * arr,uint length)
//mergesort with places
{
if(length==1) return;
mergesort(arr,length/2);
mergesort(arr,length-length/2);
merge(arr,1,length/2,length);//p,q,r
}
the result from this code :
1 2 2 4 6 50 45 23 77 6
instead of sorting the whole array is sorted only less then half