Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>At least IMO, your <code>print_out</code> isn't really working the way it should. The specific problem is that it's trying to (directly) print out data for child nodes.</p> <p>When you're dealing with a binary tree (of any sort -- unbalanced, AVL, RB, etc.) traversal will normally look roughly like this:</p> <pre><code>void print_out(node *current_node) { if current_node != NIL { show_data(current_node); print_out(current_node-&gt;left); print_out(current_node-&gt;right); } } </code></pre> <p>As is, that's pre-order; post-order or inorder is just a matter of rearranging the <code>print_data</code> compared to the recursive calls to <code>print_out</code> (for post-order it comes after them, for inorder between them).</p> <p>In particular, however, print_out should not have <em>anything</em> to do with the left or right sub-trees, other than by passing them as parameters in a recursive call. It also shouldn't normally check whether they're NIL/NULL either -- it should just make the recursive call, and let the <code>if (current_node != NIL)</code> handle in the recursive call deal with the possibility that we've hit a leaf node.</p> <p>Call me lazy if you will, but that's about as much as I'm willing to examine without at least <em>some</em> guidance about what sort of problem I'm looking for, and at least as reasonable assurance that it's the right place to look. It would be helpful (for example) if you showed that you can insert a few nodes, and get the expected structure, then show <em>what</em> goes wrong when you delete a node. Is the node still there? Are other nodes getting lost? Are all the nodes right, but the balance is wrong? If so, what's going wrong with the balance?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload