struct threadedtree{
int leftthread;
struct left;
int rightready;
struct right;
int n;
}
struct threadedtree *pre;
void InThreading(threadedtree *t){
if(t){
InThreading(t->left);
if(!t->left){
t->leftready = 1;
t->left = pre;
}
else t->leftready = 0;
if(!pre->right){
pre->right = t;
pre->rightready = 1;
}
else pre->rightready = 0;
pre = t;
InThreading(p->right);
}
}
struct threadedtree* Inorder_threading(struct threadedtree *t){
struct threadedtree* head;
head = (struct threadedtree*)malloc(sizeof(struct threadedtree));
head->right = head;
head->rightready = 0;
head->leftready = 0;
if(!t) head->left = head;
else{
head->left = t;
pre = head;
InThreading(t);
pre->right = head;
pre->right = 1;
}
}
void Inordertraversal(struct threadedtree *t){
while(t->right != t){
while(!t->leftready)
t = t->left;
visit(t);
while(t->rightready&&t->right!=t){
t = t->right;
visit(t->right);
}
t = t->right
}
}
线索二叉树的建立与遍历
最新推荐文章于 2021-12-19 19:15:42 发布