Binary tree problem, build a binary tree, traverse the tree with the middle order and the back order and output.

  c++, question

I am a beginner, the content of this question is to build a binary tree, traverse the tree with the middle order and the back order and output it. The following code comes from the book Data Structure and Algorithm Analysis except the main function. The main function comes from the teacher and is mixed after personal understanding. As a result, it failed to run on dev c++, as follows:

include<stdio.h>

include<string.h>

include<stdlib.h>

typedef struct TreeNode *SearchTree;
typedef int ElementType;
struct TreeNode;

struct TreeNode
{

ElementType Element;
 SearchTree Left;
 SearchTree Right;

};

SearchTree Insert(ElementType X,SearchTree);
void Postorder(SearchTree);
void Inorder(SearchTree);
void Visit(ElementType);

SearchTree Insert(ElementType X,SearchTree T)
{

if(T == NULL)
 {
 T=malloc(sizeof(struct TreeNode));
 if(T == NULL)
 {
 printf("Out of space!  !  !"  );
 }
 else
 {
 T->Element = X;
 T->Left = T->Right =NULL;
 }
 }
 else if(X < T->Element)
 {
 T->Left =Insert(X,T->Left);
 }
 else if(X > T->Element)
 {
 T->Right =Insert(X,T->Right);
 }

}

void Postorder(SearchTree T)
{

if(T)
 {
 Postorder(T->Left);
 Postorder(T->Right);
 Visit(T->Element);
 }

}

void Inorder(SearchTree T)
{

if(T)
 {
 Inorder(T->Left);
 Visit(T->Element);
 Inorder(T->Right);
 }

}

void Visit(ElementType T)
{

printf("%d,",T);

}

int main()
{

SearchTree T=NULL;
 int ch;
 char input[100]={0};
 scanf("%s",input);
 char *delim=",";
 char *p=strtok(input,delim);
 while(p!  =NULL)
 {
 T=Insert(atoi(p),T);
 p=strtok(NULL,delim);
 }
 Postorder(T);
 printf("\n");
 Inorder(T);
 getchar();
 getchar();
 return 0;

}

This is not the first time that I have encountered a failure to return. Previously, the pointer was wrong, but this time it was not found out. I hope the great gods can help orz. Thank you.

clipboard.png

clipboard.png

clipboard.png

Can I adjust the code format before asking questions? , even if really can’t bother to see?