title: Creating an insert function in a BST in C++
body: <p>I want to write an insert function to create a node in BST but struggling with one of the tests. Here's the instruction for the lab
  &quot;Using the class skeleton definition below, write the insert method that inserts that create a new BST node that will be used for an integer Binary Search Tree (BST). The two constructors must be functioning in your class so please make sure you have the earlier assignments working or you will not get credit for this assignment&quot;.</p>
  <p>Below is the current version of my code with the constructors already working:</p>
  <pre><code>   #include &lt;iostream&gt;
     using namespace std;
  
  class BST
  {
    public:
    int data;
    BST *left, *right;
    int nth_node(int n);
    
  
       BST(){
          data = 0;
          left = NULL;
          right = NULL;
       }
       BST(int value){}
    
  
  
      void insert(int value){
      BST* root;
      if(root == NULL){
          BST* root = new BST;
              root-&gt;data = value;
              root-&gt;left = NULL;
              root-&gt;right == NULL;
              return;
     }
      else if(value &lt; root-&gt;data){
              
                root-&gt;left-&gt;insert(value);}
  
      else if(value &gt; root-&gt;data){
              
           root-&gt;right-&gt;insert(value);
              
      }
      else{
          cout &lt;&lt;&quot;The key&quot; &lt;&lt;value&lt;&lt; &quot;exists\n&quot;;
          }
      }
   }; 
  </code></pre>
  <p>When I run this code, I get this error message
  &quot;Test Failed: 'Failed right child test' != 'Passed All Tests'</p>
  <ul>
  <li>Failed right child test</li>
  </ul>
  <ul>
  <li>Passed All Tests
  .</li>
  </ul>