#include<stdio.h>
#include<stdlib.h>
typedef struct{
    int data;
    struct node * left_child;
    struct node * right_child;
}node;

node * get_node(){
    node *tmp = (node *)malloc(sizeof(node));
    tmp->data= 0;
    tmp->left_child = NULL;
    tmp->right_child = NULL;
    return tmp;
}
void insertTree(node **root,int su){
    node *toInsert,*tmp;
    //root가 NULL일때 할당만 하고 끝냄..
    if(*root == NULL){
        *root = get_node();
        (*root)->data= su;
        return;
    }
   
    //집어 넣을 노드를 찾음.
    toInsert = *root;
    while(1){
        if(      su < toInsert->data && toInsert->left_child != NULL )
            toInsert = toInsert->left_child;
        else if( toInsert->data < su && toInsert->right_child != NULL)
            toInsert = toInsert->right_child;
        else if( toInsert->data == su)
            return;
        else{
            break;
        }
    }
       
    //집어 넣음.
   
    tmp = get_node();
    tmp->data = su;
    if(su < toInsert->data  )
        toInsert->left_child = tmp;
    else
        toInsert->right_child = tmp;
   
   
}
int main(int* argc,char* argv[]){
    node *root=NULL,*tmp;
    insertTree(&root,5);
    insertTree(&root,3);
    insertTree(&root,7);
    insertTree(&root,9);
    insertTree(&root,6);
    insertTree(&root,11);

    printf("root  - %d n",root->data);
    tmp = root->left_child;
    printf("left  - %d n",tmp->data);
    tmp = root->right_child;
    printf("right - %d n",tmp->data);
   
    tmp = tmp->right_child;
    printf("right -> right - %d n",tmp->data);
   
    tmp = tmp->right_child;
    printf("right -> right -> right - %d n",tmp->data);
}