#include <stdio.h>
#include <stdlib.h>

struct node{
    int data;
    struct node *left;
    struct node *right;
};

struct node* newNode(int num){
    struct node *nnode = (struct node*)malloc(sizeof(struct node));
    nnode->data=num;
    nnode->left=NULL;
    nnode->right=NULL;
    return nnode;
}

//print tree
void printTree(struct node *root){
    if(root==NULL) return;
    printf("%d\n",root->data);
    printTree(root->left);
    printTree(root->right);
}

struct node* insert(struct node *root, int x){
    if(root==NULL){
        struct node *nnode=(struct node*)malloc(sizeof(struct node));
    nnode->data=x;
    nnode->left=NULL;
    nnode->right=NULL;
        root=nnode;
        return root;
    }
    else{
        if(x<root->data) insert(root->left,x);
        else insert(root->right,x);
    }
}

int main()
{
    struct node *root=NULL;
    root=insert(root, 5);
    struct node* mainroot=root;
    root=insert(root, 15);
    root=insert(root, 17);
    root=insert(root, 2);
    printTree(mainroot);
    return 0;
}

