title: Root node in Binary search tree is null
body: <p>I am learning c++ and data structures
  I have implemented binary search tress
  can any body tell what is the issue in this code
  I am getting root pointer as null.
  Basically unable to create a tree.
  My final goal is to search the key in the tree. i have written a method for it. but unfortunately i am unable to create a tree. I have tested it by writing the traversal code.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;conio.h&gt;
  #include &lt;iostream.h&gt;
  
  // Node structure
  struct TreeNode {
      int value;
      int key;
      struct TreeNode *left;
      struct TreeNode *right;
  
     TreeNode()
      {
          left=NULL;
          right=NULL;
      }
  };
  
  void preOrder (TreeNode *);
  
  void insertNode(TreeNode *, int, int);
  
  TreeNode* findNode(TreeNode *aNode, int);
  
  void main() {
      TreeNode *root = NULL;
  
      for(int i = 15; i&lt;= 300; i+=15) {
          insertNode(root, i, i);
  
          if (root!=NULL) {
          cout&lt;&lt;root -&gt;value&lt;&lt;endl;
          }
      }
  
      cout&lt;&lt;"The preorder traversal"&lt;&lt;endl;
      preOrder(root);
  
      getch();
  }
  
  void preOrder (TreeNode *p) {
  
      if (p!=NULL) {
          cout&lt;&lt;p -&gt;value&lt;&lt;endl;
          preOrder(p -&gt;left);
          preOrder(p -&gt;right);
      }   else{
          cout &lt;&lt; "NULL"&lt;&lt;endl;
      }
  }
  
  void createNewNode(TreeNode *newNode, int aValue, int aKey) {
      newNode = new TreeNode; // create new node
      newNode -&gt; value = aValue; // set data
      newNode -&gt; key = aKey; // set key
            cout&lt;&lt;newNode -&gt;value&lt;&lt;endl;
      // Set left,right
      newNode -&gt; left = newNode -&gt; right = NULL;
  }
  
  void insertNode(TreeNode *aNode, int aValue, int aKey) {
  
      if (aNode == NULL) {
          TreeNode *newNode = new TreeNode; // create new node
          newNode -&gt; value = aValue; // set data
          newNode -&gt; key = aKey; // set key
          //createNewNode(newNode, aValue, aKey);
  
          if(newNode == NULL) {
              cout&lt;&lt; "Null returned"&lt;&lt;endl;
          } else {
               cout&lt;&lt; newNode -&gt; key &lt;&lt;endl;
          }
          aNode = newNode;
  
      } else if (aKey == aNode-&gt;key) {
      cout&lt;&lt;aKey&lt;&lt;endl;
          return;
  
      } else if (aKey &lt; aNode-&gt;key) {
            insertNode((aNode-&gt;left), aValue, aKey);
  
      } else {
          insertNode((aNode-&gt;right), aValue, aKey);
      }
  }
  
  TreeNode* findNode(TreeNode *aNode, int aKey) {
  
      if (aNode == NULL) {
          return NULL;
      } else if (aNode-&gt;key == aKey) {
           return aNode;
      } else if (aKey &lt;= aNode-&gt;key) {
           return findNode(aNode-&gt;left, aKey);
      } else {
           return findNode(aNode-&gt;right, aKey);
      }
  }
  </code></pre>