报错那句不知道问题在哪,调试之后发现在main函数第二个insert哪里出错
```c
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
typedef int ElementType;
struct BST;
typedef struct BST* Tree;
typedef struct BST* Position;
void MakeEmpty(Tree T);
Position Find(Tree T, ElementType X);
Position FindMin(Tree T);
Position FindMax(Tree T);
Tree Insert(Tree T, ElementType X);
Tree Delete(Tree T, ElementType X);
void PrintBST(Tree T);
struct BST
{
Position LeftChild;
Position RightChild;
ElementType Value;
};
#include "BST.h"
void MakeEmpty(Tree T) {
if (T != NULL)
{
MakeEmpty(T->LeftChild);
MakeEmpty(T->RightChild);
free(T);
}
}
Position Find(Tree T, ElementType X) {
if (T == NULL)
return NULL;
else if (X < T->Value)
return Find(T->LeftChild, X);
else if (X > T->RightChild)
return Find(T->RightChild, X);
else
return T;
}
Position FindMin(Tree T) {
if (!T->LeftChild)
return T;
else
return FindMin(T->LeftChild);
}
Position FindMax(Tree T) {
while (T->RightChild)
T = T->RightChild;
return T;
}
Tree Insert(Tree T, ElementType X) {
if (!T)
{
T = (Tree)malloc(sizeof(struct BST));
T->Value = X;
T->LeftChild = T->RightChild = NULL;
}
else if (X < T->Value)
T->LeftChild = Insert(T->LeftChild,X);
else if (X > T->Value)
T->RightChild = Insert(T->RightChild,X);
return T;
}
Tree Delete(Tree T, ElementType X) {
Position tmpcell;
if (T == NULL)
return NULL;
else if (X < T->Value)
T->LeftChild = Delete(T->LeftChild, X);
else if (X > T->Value)
T->RightChild = Delete(T->RightChild, X);
else if (T->LeftChild && T->RightChild)
{
tmpcell = FindMin(T->RightChild);
T->Value = tmpcell->Value;
Delete(tmpcell,X);
}
else
{
tmpcell = T;
if (T->LeftChild == NULL)
T = T->RightChild;
else
{
T = T->LeftChild;
}
free(tmpcell);
}
return T;
}
void PrintBST(Tree T) {
if (!T)
return;
else
{
printf("%d", T->Value);
PrintBST(T->LeftChild);
PrintBST(T->RightChild);
}
}
```c
#include "BST.h"
int main()
{
Tree T = malloc(sizeof(struct BST));
Insert(T, 7);
Insert(T, 3);
Insert(T, 8);
Insert(T, 2);
Insert(T, 5);
PrintBST(T);
}