typedef struct node* tree_pointer;
typedef struct node{
int data;
tree_pointer left_child,right_child;
};
//이진 탐색 트리의 순환적 탐색
tree_pointer search(tree_pointer root, int key){
if(!root) return NULL;
if(key == root->data) return root;
if(key < root->data)
return search(tree_pointer left_child,int key);
return search(tree_pointer right_child,int key);
}
//이진 탐색 트리의 반복적 탐색
tree_pointer search(tree_pointer tree,int key){
while(tree){
if( key == tree->data) return tree;
if( key < tree->data)
tree=tree->lefe_child;
else
tree=tree->right_child;
}
return NULL;
}
//반복적 탐색의 변형
void modified_search(tree_pointer node2,int num){
tree_pointer temp;
if(!node2) return NULL;
while(node2 !=NULL ){
if(num == node2->data) return node2;
temp=node2;
if(num < temp->data)
temp = temp->left;
else temp=temp->right;
}
}
//이진 탐색 트리에 원소를 삽입
void insert_node(tree_pointer* node,int num){
tree_pointer ptr;
temp=modified_search(*node,num);
if( temp || !(*node)){
ptr = (tree_pointer)malloc(sizeof(node));
if(IS_FULL(ptr)){
fprintf(stderr,"The memory is FULL\n");
exit(1);
}
ptr->data = num;
prt->left_child = prt->right_child = NULL;
if(*node)
if(num < temp->data)
temp->left_child = ptr;
else temp->right_child =ptr;
else *node =ptr;
}
}