Using Retrieve Method to Find for Remove, BST C++
<p>To make deletion of a leaf easier, im wondering how i can use my retreive method(which finds a node) to first retreive it before i delete. So that way i dont have to recode the same looping scheme that is in retreive:</p>

<pre><code>bool BST::retrieve(const char *key, data&amp; aData) const
{
    for ( int i = 0; i &lt; maxSize / 2; i++ )
    {//iterate
     if (! items[2*i+1].empty &amp;&amp;//proceed
        items[2*i+1].theData.getName() &lt; key )
     {// then search leftward
      if ( items[2*i+1].theData == key )
      {
       aData.setName(key);
       return true;
      }
     }
     else if (! items[2*i+2].empty &amp;&amp; 
          items[2*i+2].theData.getName() &gt; key )
     { // then search rightward
      if ( items[2*i+2].theData == key )
      {
       aData.setName(key);
       return true;
      }
     }
    }// reiterate on condition.
    return false;
}

bool BST::remove(const char* key)
{   
    this-&gt;retrieve(key, items[Position].theData );
         // get the position of the node we want to delete.
         if ( items[2*Position+1].empty &amp;&amp;
              items[2*Position+2].empty )
         {
             // then it is a leaf.
         }
}

BST::BST(int capacity) : items(new item[capacity]), Position(0), 
leftChild(0), rightChild(0), maxSize(capacity), size(0), isLeaf(0)
{

}
</code></pre>

<p>Position varaible is coming up as 0. and if i declare a plain old int "isLeaf" at the start of the retreive method, and then when we find it, assign it, "isLeaf = 2*i+1;" or "isleaf = 2*i+2".</p>

<p>I would then need to pass that POD, "isLeaf" as a paramater. Therefore, I would need a helper function for the remove method? </p>

<p>It seems that it would be extraneous to code my remove method to retreive a node..</p>

<p>Basically im after the index.</p>
