title: c++ sift down heap
body: <p>I am writing a program that requires me to use a heap, and everything runs fine besides my sorting methods, obviously quite important! I am not sure what is wrong with my logic or if I am missing something stupid. But a fresh set of eyes to look at this would be nice.</p>
  
  <p>The function is being passed my vector which is of course the heap, the location of the root, and then either the STL less or greater as a predicate. </p>
  
  <pre><code>template&lt;class T,class P&gt;
  void upheap(vector&lt;T&gt;&amp; v, int start, P func) {
     T x = v[start];
     while (start &gt; 1 &amp;&amp; func(x, v[start/2])) {
        v[start] = v[start/2]; start /= 2;
     }
     v[start] = x;
  }  
  </code></pre>
  
  <p>Any idea what is wrong?</p>