Code:

array={4,1,7,3};
int mergesort(int a[], int low, int high,int depth)
{
int mid;
printf("\nlow=%d high=%d\n",low,high);
if(low<high)
{
mid=(low+high)/2;
printf("\n(%d) before mid mid=%d
high=%d,low=%d\n",depth,mid,high,low);
mergesort(a,low,mid,depth+1);
printf("\n(%d) before mid+1 mid=%d
high=%d,low=%d\n",depth,mid,high,low);
mergesort(a,mid+1,high,depth+1);
printf("\n(%d) after mid+1 mid=%d
high=%d,low=%d\n",depth,mid,high,low);
printf("\n (%d) calling merge",depth);
printf("\n (%d) calling merge mid=%d
high=%d,low=%d\n",depth,mid,high,low);
merge(a,low,high,mid);
}
return(0);
}
Output:
low=0 high=3
(0) before mid mid=1 high=3,low=0
low=0 high=1
(1) before mid mid=0 high=1,low=0
low=0 high=0
(1) before mid+1 mid=0 high=1,low=0
low=1 high=1
(1) after mid+1 mid=0 high=1,low=0
(1) calling merge
(1) calling merge mid=0 high=1,low=0
(0) before mid+1 mid=1 high=3,low=0
low=2 high=3
(1) before mid mid=2 high=3,low=2
low=2 high=2
(1) before mid+1 mid=2 high=3,low=2
low=3 high=3
**(1) after mid+1 mid=2 high=3,low=2
(1) calling merge
(1) calling merge mid=2 high=3,low=2
(0) after mid+1 mid=1 high=3,low=0
(0) calling merge
(0) calling merge mid=1 high=3,low=0**
sorted array:
1
3
4
7

Here i would like to know how the depth variable becomes 0 after returning from calling merge()??