title: recursive quicksort, count swap and comparison issue
body: <p>I want to compare how many swaps and comparisons (&lt;, >, ==, !=) it took for a bubblesort vs. quicksort function to sort an array of unique numbers. The problem is that the quicksort function I use is recursive and I am a bit unsure how to keep track of swaps comparisons. Tried to use pointers to keep track of the count but was unsuccessful. Could anyone help me?</p>
  
  <p>my bubblesort:</p>
  
  <pre><code>void bubble_sort(int arr[], int max)
  {
      int i=0, j, temp, flag;
      int swap=0, comp=0;
      while(1)
      {
          flag = 0;
          for (j = 0 &amp;&amp; comp++;  j &lt; max - i - 1; j++)
          {
              comp++;
              if (arr[j] &gt; arr[j+1])
              {
                  swap++;
                  /* Swapping */
  
                  temp     = arr[j];
                  arr[j]   = arr[j+1];
                  arr[j+1] = temp;
                  flag=1;
              }
          }
          i++;
          comp++;
          if (flag == 0)
          {
              printf("number of swaps: %d\n",swap);
              printf("number of comparisons: %d \n\n",comp);
              break;
          }
      }
  }
  </code></pre>
  
  <p>my quicksort:</p>
  
  <pre><code>void quicksort(int arr[],int first,int last)
  {
      int pivot,j,temp,i;
  
      if(first&lt;last)
      {
          pivot=first;
          i=first;
          j=last;
  
          while(i&lt;j)
          {
              while(arr[i]&lt;=arr[pivot]&amp;&amp;i&lt;last)
                  i++;
              while(arr[j]&gt;arr[pivot])
                  j--;
              if(i&lt;j)
              {
                  temp=arr[i];
                  arr[i]=arr[j];
                  arr[j]=temp;
              }
          }
  
          temp=arr[pivot];
          arr[pivot]=arr[j];
          arr[j]=temp;
          quicksort(arr,first,j-1);
          quicksort(arr,j+1,last);
  
      }
  }
  </code></pre>
  
  <p>solution:</p>
  
  <pre><code>void quick_sort(int arr[],int first,int last, int *swap, int *comp)
  {
      int pivot,j,temp,i;
      if(++(*comp) &amp;&amp; first&lt;last)
      {
          pivot=first;
          i=first;
          j=last;
  
          while(++(*comp) &amp;&amp; i&lt;j)
          {
              while(++(*comp) &amp;&amp; arr[i]&lt;=arr[pivot]&amp;&amp;i&lt;last)
                  i++;
              while(++(*comp) &amp;&amp; arr[j]&gt;arr[pivot])
                  j--;
              if(++(*comp) &amp;&amp; i&lt;j)
              {
                  ++(*swap);
                  temp=arr[i];
                  arr[i]=arr[j];
                  arr[j]=temp;
              }
          }
          ++(*swap);
          temp=arr[pivot];
          arr[pivot]=arr[j];
          arr[j]=temp;
          quick_sort(arr,first,j-1, swap, comp);
          quick_sort(arr,j+1,last, swap, comp);
  
      }
  }
  </code></pre>