building heap in c++
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/4185139/max-heapify-procedure-on-heap">max_heapify  procedure on heap</a>  </p>
</blockquote>



<p>I am trying to build heap - here is my code:</p>

<pre><code>#include &lt;iostream&gt;
using namespace std;
int parent(int i ){
return  i/2;
}
 int left(int i ){
     return  2*i;

}
int right(int i){
 return 2*i+1;

}
int a[]={4,1,3,2,16,9,10,14,8,7};
int n=sizeof(a)/sizeof(int);
void max_Heapify(int i){
int largest=i;
    int l=left(i);
int r=right(i);
if ( l&gt;=n ||  r&gt;=n){  return ;}
  if(l&lt;n &amp;&amp; a[l]&gt;a[i]){
   largest=l;

}
else{
largest=i;
}
if(r&lt; n &amp;&amp; a[r]&gt;a[largest]){
  largest=r;

}
  if (largest!=i){
int t=a[i];
a[i]=a[largest];
a[largest]=t;
 max_Heapify(largest);
}

}
int main(){
   for (int i=n/2;i&gt;0;i--){

    max_Heapify(i);
   }
    for (int i=0;i&lt;n;i++){
     cout&lt;&lt;a[i]&lt;&lt;" ";

    }
return 0;
}
</code></pre>

<p>but something is wrong, it stops abnormally - why?</p>
