title: Binary Search Tree recursion insertion
body: <p>I'm currently having difficulty inserting a node into a binary tree using recursion. I've been dwelling on this problem for a few days now and thought it was time I came looking for answers!</p>
  
  <p>Node class (.h):</p>
  
  <pre><code>#ifndef STUDENT_MACROGUARD
  #define STUDENT_MACROGUARD
  
  #include &lt;cstdlib&gt;
  #include &lt;string&gt;
  
  namespace student_class
  {
      class student
      {
          public:
              // Constructors / Destructors;
  
              student(const float entry = 0, std::string name = "", 
                          student* left_ptr = NULL, student* right_ptr = NULL);
              ~student(void){};
  
              // Mutating member functions;
  
              void set_grade(const float entry);
              void set_name(std::string entry);
  
              void set_left(student* node_ptr);
              void set_right(student* node_ptr);
  
              // Non mutating member functions;
  
              float grade(void);
              std::string name(void);
  
              student* left(void);
              student* right(void);
  
              // Const member functions;
  
              const student* left(void) const;
              const student* right(void) const;
  
      private:
              std::string student_name;
              float grade_field;
              student* left_ptr;
              student* right_ptr;
      };
  }
  
  #endif
  </code></pre>
  
  <p>BSTree class to implement the Binary Tree data structure (.h):</p>
  
  <pre><code>#ifndef BTTree_MACROGUARD
  #define BTTree_MACROGUARD
  
  #include &lt;cstdlib&gt;
  #include &lt;string&gt;
  #include &lt;iostream&gt;
  #include "student.h"
  
  using namespace student_class;
  
  namespace BTTree_class
  {
  class BTTree
  {
      public:
              // Constructors / Destructors; 
  
              BTTree(student* node_ptr = NULL);
              ~BTTree(void);
  
              // Mutating member functions;
  
              void insert(student* node_ptr = NULL, const float grade = 0, std::string name = "");
              void remove(student* node_ptr);
  
              // Non mutating member functions;
  
              student* grade_search(const float entry);
              student* name_search(const std::string entry);
              student* root(void);
              void print_tree(student* node_ptr);
  
              // Const member functions;
  
              const student* grade_search(const float entry) const;
              const student* name_search(const float entry) const;
              const student* root(void) const;
  
      private:
              student* root_ptr;
      };
  }
  
  #endif
  </code></pre>
  
  <p>The insert member function implementation I'm using to insert nodes into the tree:</p>
  
  <pre><code>    void BTTree::insert(student* node_ptr, const float grade, std::string name)
  {
      if(root_ptr == NULL)
      {
          root_ptr = new student(grade, name);
          return;
      }
  
      if(node_ptr == NULL)
      {
          node_ptr = new student(grade, name);
          return;
      }
      else if(node_ptr-&gt;grade() &gt; grade)
      {
          insert(node_ptr-&gt;left(), grade, name);
      }
      else
      {
          insert(node_ptr-&gt;right(), grade, name);
      }
  }
  </code></pre>
  
  <p>I don't understand why this insertion isn't working. The code looks flawless and it's left me scratching my head. I've written an alternate insertion function which uses iteration, but recursion is a must.</p>
  
  <p>Any help would be fantastic, thank you. </p>