//创建二叉树和三种遍历,输入序列如 1 5 8 0 0 0 6 0 0
#include <stdio.h>
#include <iostream>
using namespace std;
struct Node{
int data;
Node* left;
Node* right;
};
Node* create(void){
int x;
cin>>x;
if(x==0){
return NULL;
}
Node *T = new Node;
T->data = x;
T->left = create();
T->right =create();
}
void preOrder(Node * T){
if(T==NULL)
return;
cout<<T->data<<' ';
preOrder(T->left);
preOrder(T->right);
}
void midOrder(Node * T){
if(T==NULL)
return;
midOrder(T->left);
cout<<T->data<<' ';
midOrder(T->right);
}
void postOrder(Node * T){
if(T==NULL)
return;
postOrder(T->left);
postOrder(T->right);
cout<<T->data<<' ';
}
int main(){
//Node* root = new Node;
Node * root =create();
preOrder(root);
printf("\n");
midOrder(root);
printf("\n");
postOrder(root);
return 0;
}//创建二叉树和三种遍历,输入序列如 1 5 8 0 0 0 6 0 0