typedef struct _tree{
int nodecontent;
struct _tree *leftchild;
struct _tree *rightchild;
int Ltag,Rtag;
}TREE;
typedef TREE* PTREE;
PTREE CrtTree(DATATYPE value){
PTREE proot;
proot=(PTREE)malloc(sizeof(TREE));
assert(proot);
proot->nodecontent=value;
proot->leftchild=NULL;
proot->rightchild=NULL;
proot->Ltag = 0;
proot->Rtag = 0;
return proot;
}
void InsertNode(DATATYPE value,PTREE root){
PTREE crrt=root;
PTREE *p=&crrt;
while(*p != NULL){
if(value == crrt->nodecontent){
return;
}
if(value < crrt->nodecontent){
p = &crrt->leftchild;
crrt = crrt->leftchild;
}
else{
p = &crrt->rightchild;
crrt = crrt->rightchild;
}
}
*p = CrtTree(value);
}
int FindTree(PTREE root, DATATYPE value){
PTREE crrt=root;
while( crrt != NULL){
if(value == crrt->nodecontent){
printf("there's this value in the tree\n");
return 1;
}
if(value < crrt->nodecontent){
crrt = crrt->leftchild;
}
else{
crrt = crrt->rightchild;
}
}
printf("there's no this value in the tree\n");
return 0;
}
void PreOrder(PTREE bt){
if(bt){
printf("%d ",bt->nodecontent);
PreOrder(bt->leftchild);
PreOrder(bt->rightchild);
}
return;
}
void MidOrder(PTREE bt){
if(bt){
MidOrder(bt->leftchild);
printf("%d ",bt->nodecontent);
MidOrder(bt->rightchild);
}
return;
}
void PosOrder(PTREE bt ) {
if(bt){
PosOrder(bt->leftchild);
PosOrder(bt->rightchild);
printf("%d ",bt->nodecontent);
}
return;
}
void Clear(PTREE bt) {
if(bt){
Clear(bt->leftchild);
Clear(bt->rightchild);
free(bt);
bt=NULL;
}
return;
}
int MMax(int a,int b){
return a>b?a:b;
}
int TreeDeeps(PTREE bt){
if(bt == NULL) return 0;
return MMax(TreeDeeps(bt->leftchild),TreeDeeps(bt->rightchild))+1;
}
PTREE Mid_pre = NULL;
void midThreadTree(PTREE bt){
if(bt == NULL) return;
if(bt->leftchild != NULL){
midThreadTree(bt->leftchild);
}
else{
bt->Ltag = 1;
bt->leftchild = Mid_pre;
}
if(Mid_pre!=NULL&&Mid_pre->rightchild==NULL){
Mid_pre->rightchild = bt;
Mid_pre->Rtag = 1;
}
Mid_pre = bt;
midThreadTree(bt->rightchild);
}
PTREE MidFirstView(PTREE bt){
while(bt->Ltag==0) bt = bt->leftchild;
return bt;
}
PTREE MidNextView(PTREE bt){
if(bt->Rtag == 1 || bt->rightchild == NULL) return bt->rightchild;
return MidFirstView(bt->rightchild);
}
int ViewThreadTree(PTREE bt){
for(bt = MidFirstView(bt);bt!=NULL;bt = MidNextView(bt))
printf("%d ",bt->nodecontent);
}
int main(){
}