title: Adjust heap function causes index range assertion to fail
body: <p>I've built an adjust heap function, but my <code>assert(position &lt; array-&gt;size)</code> is failing and I can't figure out why.</p>
  
  <pre><code>void adjustHeap(DynamicArray* heap, int max, int pos, compareFunction compare)
  {
      // FIXME: implement
      int leftChild = 2 * pos + 1;
      int rightChild = 2 * pos + 2;
      int idxSmallest = indexSmallest(heap, leftChild, rightChild);
      if(rightChild &lt; max) { /* we have two children */
          if(dyGet(heap, pos) &gt; dyGet(heap, idxSmallest)) {
              dySwap(heap,pos,idxSmallest);
              adjustHeap(heap, max, idxSmallest, compare);
          }
      }
      else if (leftChild &lt; max) { /* we have one child */
          if(dyGet(heap, pos) &gt; dyGet(heap, leftChild)) {
              dySwap(heap,pos,leftChild);
              adjustHeap(heap, max, leftChild, compare);
          }
      }
      else {
          return;
      }
  }
  </code></pre>
  
  <p>My <code>dyGet()</code> function:</p>
  
  <pre><code>TYPE dyGet(DynamicArray* array, int position)
  {
      assert(position &lt; array-&gt;size);
      return array-&gt;data[position];
  }
  </code></pre>
  
  <p>My <code>assert(position &lt; array-&gt;size)</code> is failing in <code>dyGet()</code> using the following test:</p>
  
  <pre><code>void testAdjustHeap(CuTest* test)
  {
      const int n = 100;
      Task* tasks = createTasks(n);
      for (int j = 0; j &lt; n; j++)
      {
          DynamicArray* heap = dyNew(1);
          for (int i = 0; i &lt; n; i++)
          {
              dyAdd(heap, &amp;tasks[i]);
          }
          for (int i = 0; i &lt; n; i++)
          {
              dyPut(heap, &amp;tasks[rand() % n], 0);
              adjustHeap(heap, dySize(heap) - 1, 0, taskCompare);
              assertHeapProperty(test, heap);
          }
          dyDelete(heap);
      }
      free(tasks);
  }
  </code></pre>
  
  <p>'indexSmallest' function:</p>
  
  <pre><code>int indexSmallest(struct DynamicArray * v, int i, int j) { /* return index of smallest element */
      if(i &lt; j) {
          return i;
      }
      return j;
  }
  </code></pre>