typedef struct node { int data; struct node *lchild, *rchild; }bitnode, *bitree; bool search(bitree T, int x, bitree f, bitree *p){ // 查找应该插入的位置 if (!T) { *p = f; return false; } else if (T->data == x){ *p = T; return true; } else if (T->data > x) return search(T->lchild, x, T, p); else return search(T->rchild, x, T, p); } bool creat(bitree *T, int x){ // 创建一棵二叉排序树 bitree p, s; if (search(*T, x, NULL, &p)) return false; else { s = (bitnode *)malloc(sizeof(bitnode)); s->data = x; s->lchild = s->rchild = NULL; if (!p) *T = s; else if (x < p->data) p->lchild = s; else p->rchild = s; return true; } } void delet(bitree *T){ if ((*T)->lchild == NULL && (*T)->rchild == NULL) (*T) = NULL; else if ((*T)->lchild == NULL) (*T) = (*T)->rchild; else if ((*T)->rchild == NULL) (*T) = (*T)->lchild; else { bitree L = (*T)->lchild; while(L->rchild){ L = L->rchild; } L->rchild = (*T)->rchild; (*T) = (*T)->lchild; } } void deletbit(bitree *T, int x){ if (!(*T)) return; else if ((*T)->data == x) { delet(T); return; } else if ((*T)->data > x) deletbit(&(*T)->lchild, x); else deletbit(&(*T)->rchild, x); }