title: How do I optimize this postfix expression tree for speed?
body: <p>Thanks to the help I received in <a href="https://stackoverflow.com/questions/2761918/how-do-i-use-this-in-a-member-function]">this</a> post:</p>
  
  <p>I have a nice, concise recursive function to traverse a tree in postfix order:</p>
  
  <pre><code>deque &lt;char*&gt; d;
  void Node::postfix()
  {
      if (left != __nullptr) { left-&gt;postfix(); } 
      if (right != __nullptr) { right-&gt;postfix(); } 
      d.push_front(cargo);
      return;
  };
  </code></pre>
  
  <p>This is an expression tree. The branch nodes are operators randomly selected from an array, and the leaf nodes are values or the variable 'x', also randomly selected from an array.</p>
  
  <pre><code>char *values[10]={"1.0","2.0","3.0","4.0","5.0","6.0","7.0","8.0","9.0","x"};
  char *ops[4]={"+","-","*","/"};
  </code></pre>
  
  <p>As this will be called billions of times during a run of the genetic algorithm of which it is a part, I'd like to optimize it for speed. I have a number of questions on this topic which I will ask in separate postings.</p>
  
  <p>The first is: how can I get access to each 'cargo' as it is found. That is: instead of pushing 'cargo' onto a deque, and then processing the deque to get the value, I'd like to start processing it right away. </p>
  
  <p>Edit: <a href="https://stackoverflow.com/questions/1451304/python-generators-in-various-languages">This</a> question suggests that processing the deque afterwards is a better way.</p>
  
  <p>I don't yet know about parallel processing in c++, but this would ideally be done concurrently on two different processors.</p>
  
  <p>In python, I'd make the function a generator and access succeeding 'cargo's using .next(). </p>
  
  <p>See the above Edit.</p>
  
  <p>But I'm using c++ to speed up the python implementation. I'm thinking that this kind of tree has been around for a long time, and somebody has probably optimized it already. Any Ideas? Thanks</p>