title: inorder and preorder traversal using recursion - binary search tree c++
body: <p>so i need to implement a member function, pre-order and inorder traversal of a binary search tree using recursion. i'm having trouble implementing all three, since they're coming out with the wrong outputs. The traversals are supposed to add data values it encounters to a given linked list.</p>
  
  <p>My member function only prints out the right nodes of the tree. I have attached my code, and it would be amazing if someone could give me some pointers as to where the errors lie and why the output is not printing what it's supposed to be. Thanks in advance!!!</p>
  
  <p><strong>Output I currently get:</strong></p>
  
  <pre><code>size of test BinaryTree: 11  
  member true for 8  
  member true for 38  
  member true for 39  
  member true for 45  
  pre order: [8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 38, 38, 38, 38, 38, 38, 38, 38, 39, 39, 45, 45]  
  in order: [8, 8, 8, 8, 38, 38, 38]
  </code></pre>
  
  <p><strong>Output I want:</strong></p>
  
  <pre><code>size of test BinaryTree: 11  
  member true for 1  
  member true for 3  
  member true for 4  
  member true for 7  
  member true for 8  
  member true for 16  
  member true for 31  
  member true for 33  
  member true for 38  
  member true for 39  
  member true for 45  
  pre order: [8, 4, 3, 1, 7, 38, 31, 16, 33, 39, 45]  
  in order: [1, 3, 4, 7, 8, 16, 31, 33, 38, 39, 45]
  </code></pre>
  
  <p>My code:</p>
  
  <pre><code>bool BinaryTreeNode::member(Data * newData) {
     if (newData-&gt;compareTo(this-&gt;nodeData) == 0) {
             return true;
      }
     else if (newData-&gt;compareTo(this-&gt;nodeData) == -1) {
           if (left == NULL)
               return false;
          else
               return left-&gt;member(newData);
  }
     else if (newData-&gt;compareTo(this-&gt;nodeData) == 1) {
          if (right == NULL)
             return false;
          else
             return right-&gt;member(newData);
  }
  return false;
      }        
  
      void BinaryTreeNode::preorderTraversal(LinkedList * result) const {
      result-&gt;insert(nodeData);
          if (left != NULL) left-&gt;preorderTraversal(result);
      result-&gt;insert(nodeData);
      if (right != NULL) right-&gt;preorderTraversal(result);
          }
  
      void BinaryTreeNode::inorderTraversal(LinkedList * result) const {
      if (left != NULL) {
           left-&gt;inorderTraversal(result);
           result-&gt;insert(nodeData);
      }
      if (right != NULL) {
           right-&gt;inorderTraversal(result);
      }
      }
  </code></pre>