Professional Documents
Culture Documents
void CreateTREE(TREE &root) { int x; printf("\nNhap gia tri node :"); scanf("%d",&x); if (x!=0) { root=(NODE*)malloc(sizeof(NODE)); root ->data=x; printf("\n Con trai cua %d (Enter 0)",x); CreateTREE(root->left); printf("\n Con phai cua %d (Enter 0)",x); CreateTREE(root->right); } else root=NULL; }
//Tim node, co thi tra ve dia chi khong thi tra ve NULL
TREE timkiem(TREE root, int x) { TREE p; if (root==NULL) return NULL; else { if (root->data==x) return root; { p=timkiem(root->left,x); if (p!=NULL) return p; return timkiem(root->right,x); } } }
void delnodela(TREE &root) { if (root==NULL) return; if (root->Left==NULL && root->Right==NULL) { delete root; root=NULL; return; } delnodela(root->Left); delnodela(root->Right); }