typedef struct BST { int key; BST *left; BST *right; }BST; BST *root; void insert(BST *ROOT,int key) { BST *p,*f; p = ROOT; f = NULL; while ( p != NULL ) { if ( key < p->key ) { f = p; p = p->left; } else { f = p; p = p->right; } } BST *tmp; if ( f == NULL ) { root = (BST *)malloc(sizeof(BST)); root->key = key; root->left = root->right = NULL; } else if ( key < f->key ) { tmp = (BST *)malloc(sizeof(BST)); f->left = tmp; tmp->key = key; tmp->left = tmp->right = NULL; } else { tmp = (BST *)malloc(sizeof(BST)); f->right = tmp; tmp->key = key; tmp->left = tmp->right = NULL; } }