title: Counting the number of comparisons done in Heapsort
body: <p>I am trying to count the number of comparisons done by heap sorting algorithm. 
  my code is based on priority queue and I want to know where I should put the counter. here is what I have but when I try to print the counter it shows zero counts, what am I doing wrong? Thank you.</p>
  
  <p>here is the heapbuild  function: </p>
  
  <pre><code>#include&lt;iostream&gt;
  
  vector&lt;int&gt; pq_keys;
  void buildHeap()
  {
  int size = pq_keys.size();
  int midIdx = (size -2)/2;
  while (midIdx &gt;= 0)
  {      
      shiftRight(midIdx, size-1);     
      --midIdx;
  }
  </code></pre>
  
  <p>and this is the function that does the comparison: </p>
  
  <pre><code>int shiftRight(int low, int high)
  {
    int root = low;
    int counter=0;
    while ((root*2)+1 &lt;= high)
      {
        int leftChild = (root * 2) + 1;
        int rightChild = leftChild + 1;
        int swapIdx = root;
        if (pq_keys[swapIdx] &lt; pq_keys[leftChild])
      {
        counter++;
        cout&lt;&lt;counter;
        swapIdx = leftChild;
  
      }
      /*If right child exists check if it is less than current root*/
      if ((rightChild &lt;= high) &amp;&amp; (pq_keys[swapIdx] &lt; pq_keys[rightChild]))
      {
      counter++;
      swapIdx = rightChild;    
      }
      /*Make the biggest element of root, left and right child the root*/
      if (swapIdx != root)
      { 
      counter++;
      int tmp = pq_keys[root];
      pq_keys[root] = pq_keys[swapIdx];
      pq_keys[swapIdx] = tmp;
      root = swapIdx;
      }
      else
      {
          break;
      }
  }
  
  return counter;
  
  }
  </code></pre>