struct ThreadNode{ int data; ThreadNode *lchild, *rchild; int ltag, rtag; }; void InThread(ThreadNode *p, ThreadNode *pre){ if(p != NULL){ InThread(p->lchild, pre); if(p->lchild == NULL){ p->lchild = pre; p->ltag = 1; } if(pre != NULL && pre->rchild == NULL){ pre->rchild = p; pre->rtag = 1; } pre = p; InThread(p->rchild, pre); } } void CreateInThread(ThreadNode *T){ ThreadNode *pre = NULL; if(T != NULL){ InThread(T, pre); pre->rchild = NULL; pre->rtag = 1; } } void InPre(ThreadNode *T, ThreadNode* pre){ if(T->ltag == 1) pre = T->lchild; else{ ThreadNode* p; for(p = T->lchild; p->rtag == 0; p = p->rchild); pre = p; } } void InNext(ThreadNode *T, ThreadNode* next){ if(T->rtag == 1) next = T->rchild; else{ ThreadNode* p; for(p = T->rchild; p->ltag == 0; p = p->lchild); next = p; } }