title: Heap sort heapify sort
body: <p>I have a problem witch Heap Sort. I don't know what is wrong in my code. This program changed only second and last position in a table. This is my code (without main function):</p>
  
  <pre><code>   #include&lt;stdio.h&gt;
  #define DUZO 100000000
  int heap_size;
  int tab[DUZO];
  
  void heapify(int start){
      int l, r, largest, pom;
  
      l = 2*start + 1;
      r = 2*start + 2;
  
      if((l &lt; heap_size) &amp;&amp; (tab[l] &gt; tab[start]))
          largest = l;
      else
          largest = start;
  
      if((r &lt;  heap_size) &amp;&amp; (tab[r] &gt; tab[largest]))
          largest = r;
      if(largest != start){
          pom = tab[start];
          tab[start] = tab[largest];
          tab[largest] = pom;
  
          heapify(largest);
      }
  }
  
  void build_max(){
      int lenght, i;
      lenght = heap_size;
  
      for(i = ((lenght - 1)/2); i &gt;= 0; --i){
          heapify(i);
      }
  }
  
  void heap_sort(){
      int i;
      build_max();
  
  
      for(i = heap_size-1; i &gt; 0; --i) {
          int tmp = tab[0];
          tab[0] = tab[i];
          tab[i] = tmp;
          --heap_size;
          heapify(0);
      }
  }
  </code></pre>
  
  <p>Thanks for all help.</p>