title: C++ Binary Tree Printing Nodes
body: <p>I'm learning about binary trees. I was looking at Stanford website:
  <a href="http://cslibrary.stanford.edu/110/BinaryTrees.html" rel="nofollow">http://cslibrary.stanford.edu/110/BinaryTrees.html</a>
  There was a practice problem of making a tree by calling newNode() three times, and using three pointer variables.
  The struct and newNode were given. I was trying to print out the nodes. </p>
  
  <pre><code>struct node { 
      int data; 
      struct node* left; 
      struct node* right; 
  } ;
  
  /* 
   Helper function that allocates a new node 
   with the given data and NULL left and right pointers. 
  */ 
  struct node* newNode(int data) { 
    struct node* node = new(struct node); 
    node-&gt;data = data; 
    node-&gt;left = NULL; 
    node-&gt;right = NULL;
  
    return(node); 
  }; 
  
  // call newNode() three times 
  struct node* build123a() { 
    struct node* root = newNode(2); 
    struct node* lChild = newNode(1); 
    struct node* rChild = newNode(3);
    root-&gt;left = lChild; 
    root-&gt;right= rChild;
  
    return(root); 
  }
  
  int main() {
  
      struct node* test = build123a();
      cout &lt;&lt; "root: " &lt;&lt; test-&gt;data &lt;&lt; endl;
      cout &lt;&lt; "left: " &lt;&lt; test-&gt;left &lt;&lt; endl;
      cout &lt;&lt; "right: " &lt;&lt; test-&gt;right &lt;&lt; endl;
  
      return 0;
  }
  </code></pre>
  
  <p>The issue is that this prints out only the integer in root.
  For the left and right nodes, it prints out address locations. 
  My knowledge of pointers is still a little shaky. But it shouldn't matter that I've only returned root right? newNode is a pointer to a node right?
  Just looking for a simple fix to print out left and right nodes. </p>