线索二叉树,求助大佬
#include<stdio.h>#include<stdlib.h>
typedef enum {Link,Thread} point;
typedef struct Treenode {
point LFlag, RFlag;
int data;
struct Treenode* lchild, * rchild;
}node,*Tree;
void BuildTree(Tree* L)
{
*L = NULL;
return;
}
void CreateTree(Tree* L)
{
char c;
scanf_s("%c", &c);
if (c == ' ') {
*L = NULL;
}
else {
*L = (Tree)malloc(sizeof(Treenode));
(*L)->data = c;
(*L)->LFlag = Link;
(*L)->RFlag = Link;
CreateTree(&(*L)->lchild);
CreateTree(&(*L)->rchild);
}
}
Tree pre;
void OrderThreading(Tree* L)
{
if (L)
{
if (!(*L)->lchild) {
(*L)->LFlag = Thread;
(*L)->lchild = pre;
}
if (!(*L)->rchild) {
(*L)->RFlag = Thread;
(*L)->rchild = (*L);
}
pre= (*L);
OrderThreading(&((*L)->lchild));
OrderThreading(&((*L)->rchild));
}
}
void OrderTree(Tree L)
{
if (L) {
printf("%c", L->data);
L = L->lchild;
if (L->LFlag == Link) {
L = L->lchild;
}
if (L->RFlag == Thread && L->rchild != L) {
L = L->rchild;
printf("%c", L->data);
}
L = L->rchild;
}
}
int main()
{
Tree tree ;
BuildTree(&tree);
CreateTree(&tree);
OrderThreading(&tree);
OrderTree(tree);
}
运行不了啊,那个OrderThreading函数的参数L,好像传不进去,还是怎么回事,求大佬帮忙(vs2019) void CreateTree(Tree* L)
{
char c;
scanf_s("%c", &c);
fflush(stdin);/////////////
if (c == ' ') {
*L = NULL;
}
else {
*L = (Tree)malloc(sizeof(Treenode));
(*L)->data = c;
(*L)->LFlag = Link;
(*L)->RFlag = Link;
CreateTree(&(*L)->lchild);
CreateTree(&(*L)->rchild);
}
}
Tree pre;
void OrderThreading(Tree* L)//不知道这个函数干啥的,怎么弄成了死循环
{
if (L)
{
if (!(*L)->lchild) {//假如(*L)->lchild为空(*L)->lchild = pre;
(*L)->LFlag = Thread;
(*L)->lchild = pre;
}
if (!(*L)->rchild) {//假如(*L)->rchild为空,(*L)->rchild = (*L);
(*L)->RFlag = Thread;
(*L)->rchild = (*L);
}
pre= (*L);
OrderThreading(&((*L)->lchild));//最后递归死循环,因为参数L永远不为空
OrderThreading(&((*L)->rchild));
}
}
页:
[1]