Hie,I have Merge Sort Program .It's giving correct output but when checked through debugger it gives different values everytime.I also tried doing it manually but I am not getting the actual output. I will not ask now for complete program explanation. I just want to know the value over here.This is the half program.

#include<stdio.h>
int main()
{
int i,low,high,n,a[10];
printf("how many elements");
scanf("%d",&n);
printf("\nEnter the elements");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
low=0;
high=n-1;
msort(a,low,high);
printf("The sorted array is ");
for(i=0;i<n;i++)
printf("\n%d",a[i]);
return 0;
}
msort(int a[],int low,int high)
{
int mid;
if(low<high)
{
mid=(low+high)/2;
msort(a,low,mid); // values are correct here
msort(a,mid+1,high); // I am stuck here
merge(a,low,mid,high);
}

Considering array values are 3,12,4,9,5.
The place wherein I wrote I am stuck. According to me,when control moves at msort(a,mid+1,high) ,
value of mid is 2 then 3 and value of low is 3 then 4 and value of high remains 4.
Hope to get some help. Thank you.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.