title: Counting the number of comparisons for merge sort
body: <p>So this is my code for a merge sort. But I need to find out how many times the comparisons were made during the merge function. For my code, the count output would be 0. How should I change the code to make the counter working?</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  #include&lt;stdlib.h&gt;
  
  void merge(int *array,int low, int mid, int high,int count)
  {
    int i=low, j=mid+1, n=low, f[high+1];
  
    while((i&lt;=mid)&amp;&amp;(j&lt;=high)) {
      if(array[i]&gt;array[j]){
            f[n]=array[j];
            j++;
        }else{
            f[n]=array[i];
            i++;
        }
      n++;
      count++;
    }
  
    if(i&gt;mid)
    while(n&lt;=high) {
      f[n]=array[j];
      n++;
      j++;
      }
  
    if(j&gt;mid)
    while(n&lt;=high) {
      f[n]=array[i];
      n++;
      i++;
      }
    for(n=low;n&lt;=high;n++)
        array[n]=f[n];
  }
  
  
  void mergesort(int *array, int low, int high,int count)
  {
    int mid;
    if(low&lt;high){
        mid=(high+low)/2;
        mergesort(array,low,mid,count);
        mergesort(array,mid+1,high,count);
        merge(array, low, mid, high,count);
       }
  } 
  
  int main()
  {
    int size,i, count=0, *f;
    scanf("%d", &amp;size);
    f=(int *)malloc(sizeof(int)*size);
    for(i=0;i&lt;size;i++)
      scanf("%d", &amp;f[i]);
    mergesort(f, 0, size-1,count);
    for(i=0;i&lt;size;i++) {
        printf("%d",f[i]);
        if(i==size-1)
          printf("\n");
        else
          printf(" ");
      }
    printf("%d\n", count);
    return 0;
  }
  </code></pre>