title: Recursive insertion of BST
body: <p>I have made a function for insertion in BST using loops and it is working perfectly fine.
  Now, when iam writing to do it using recursion i don't know why it's not working properly, however the logic is correct according to me. It seems that no newnode is being added to the BST tree and head of the tree after coming out of the insertion function is again becoming NULL.</p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  
  class node{
  public:
     int data;
     node *right;
     node *left;
     node(){
        data=0;
        right=NULL;
        left=NULL;
     }
  };
  
  class tree{
     node *head;
     int maxheight;
     void delete_tree(node *root);
  public:
     tree(){head=0;maxheight=-1;}
     void pre_display(node* root);
     node* get_head(){return head;}
     void insert(int key,node* current);
  };
  
  void tree::insert(int key,node *current){
     if(current==NULL)
     {
        node *newnode=new node;
        newnode-&gt;data=key;
        current=newnode;
     }
     else{
        if(key&lt;current-&gt;data)
           insert(key,current-&gt;left);
        else
           insert(key,current-&gt;right);
     }
     return;
  }
  
  void tree::pre_display(node *root){
     if(root!=NULL)
     {
        cout&lt;&lt;root-&gt;data&lt;&lt;" ";
        pre_display(root-&gt;left);
        pre_display(root-&gt;right);
     }
  }
  
  int main(){
     tree BST;
     int arr[9]={17,9,23,5,11,21,27,20,22},i=0;
  
     for(i=0;i&lt;9;i++)
     BST.insert(arr[i],BST.get_head());
  
     BST.pre_display(BST.get_head());
     cout&lt;&lt;endl;
  
     system("pause");
     return 0;
  }
  </code></pre>
  
  <p>Please tell me what should i change in the algorithm to make it work.</p>