title: Binary Search Tree Data in Nodes always is zero
body: <p>I've been working on my Binary search tree for a while and the functions seem to work but I'm running into the same problem I had when I had a linked list program assignment. My nodes don't seem to want to store data. I can't figure out what the problem is. When I print it only prints zeros, the correct number of zeros, but still just zeros. Here's my code for my node. I should mention this is C++.</p>
  
  <pre><code>class Node{
      friend class BST;
      private:
      int data;
      Node *left;
      Node *right;
      public:
      Node(int data);   
  };
  </code></pre>
  
  <p>My add function is:</p>
  
  <pre><code>void BST::add(Node* node, int d) {
      if (root == NULL) {
          root = new Node(d);
      }
      else if (d &lt;= node-&gt;data) {
          if (node-&gt;left == NULL) {
              node-&gt;left = new Node(d);
          }
          else {
              add(node-&gt;left, d);
          }
      }
      else if (d &gt; node-&gt;data) {
          if (node-&gt;right == NULL) {
              node-&gt;right = new Node(d);
          }
          else {
              add(node-&gt;right, d);
          }
      }
  }
  </code></pre>
  
  <p>Why won't it store data?</p>