title: C++ Expression Tree Simplification
body: <p>I'm having trouble simplifying an expression tree string. I've tried using stacks to separate parenthesis from elements then popping any unnecessary parentheses, but at this point I've just created a mess and am trying to start back from scratch, so if I'm given the expression:</p>
  
  <pre><code>Input: (AB)C((DE)F)
  </code></pre>
  
  <p>(I assume this is what the tree looks like):
  <a href="https://i.stack.imgur.com/2x5A0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2x5A0.png" alt="Desired tree"></a>
  With that string and that tree my output should be:</p>
  
  <pre><code>Output: ABC(DEF)
  </code></pre>
  
  <p>I just don't understand how to get from the input to the output.</p>