启动调试直接显示segmentation fault了,是这个递归写的不对吗
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
struct Node;
typedef char ElementType;
typedef struct Node *Position;
typedef struct Node *Tree;
Tree Initialize();
void InsertLeft(Position N,ElementType value);
void InsertRight(Position N,ElementType value);
bool IsLeaf(Position N);
void SetValue(Position N,ElementType value);
void MiddleScan(Position N);
struct Node
{
ElementType value;
Position LeftChild;
Position RightChild;
};
```c
#include "BinaryTree.h"
Tree Initialize()
{
Tree T = (Tree)malloc(sizeof(struct Node));
T->LeftChild = NULL;
T->RightChild = NULL;
T->value = ' ';
return T;
}
void InsertLeft(Position N,ElementType value)
{
Position New;
if (N->LeftChild)
N->value = value;
else
New = malloc(sizeof(struct Node));
New->RightChild = New->LeftChild =NULL;
New->value = value;
N->LeftChild = New;
}
void InsertRight(Position N,ElementType value)
{
Position New;
if (N->RightChild)
N->value = value;
else
New = malloc(sizeof(struct Node));
New->RightChild = New->LeftChild =NULL;
New->value = value;
N->RightChild = New;
}
bool IsLeaf(Position N)
{
return (N->LeftChild || N->RightChild);
}
void SetValue(Position N,ElementType value)
{
N->value = value;
}
void MiddleScan(Tree N)
{
if (N->LeftChild == NULL && N->RightChild == NULL)
printf("%c",N->value);
else
MiddleScan(N->LeftChild);
printf("%c",N->value);
MiddleScan(N->RightChild);
}
int main()
{
Tree T0 = Initialize();
SetValue(T0,'a');
InsertLeft(T0,'b');
InsertRight(T0,'c');
MiddleScan(T0);
system("pause");
return 0;
}
![img](https://img-mid.csdnimg.cn/release/static/image/mid/ask/025215898436183.png "=600 #left")