title: Constructing a binary tree using queue in C++
body: <p>I am trying to write some data structure HW in C++. When I was trying to construct a binary tree using a queue, I was somehow confused by the pointer issues. </p>
  
  <pre><code>class Tree{
  private:
      struct TreeNode{
      int val;
      TreeNode* left;
      TreeNode* right;
  
      TreeNode(int x) :val(x), left(NULL), right(NULL) {}
  };
  public:
      TreeNode* root = NULL;       
      Tree();
      Tree(queue&lt;int&gt;&amp; val);       
      ~Tree();
      string toString_bf();
  };
  
  
  Tree(queue&lt;int&gt; &amp;vals){
      if (vals.empty())
          return;
  
      root = new TreeNode(vals.front());
      vals.pop();
      queue&lt;TreeNode**&gt; pts;       // what is the meaning of this? Why should use pointers to pointer?
  
      pts.push(&amp;(root-&gt;left));     // also have doubts here, about the reference used in the parameter
      pts.push(&amp;(root-&gt;right));
      while (!vals.empty()){
          TreeNode* t = new TreeNode(vals.front());
          *(pts.front()) = t;      // and here
          pts.pop();
          vals.pop();
          pts.push(&amp;(t-&gt;left));
          pts.push(&amp;(t-&gt;right));
      }
  }
  </code></pre>
  
  <p>According to my understanding, left and right are both pointers, why could not just pass values to them?</p>