/* * Example DBA,,C,,E,GF,,, */#include <cstdio> #include <cstdlib> #include <cmath> #include <map># include<queue> #include <stack> #include <vector> #include <algorithm> #include <cstring > #include <string> #include <iostream> #define MS (x, y) memset (x,y,sizeof (×)) const int maxn=1000+10; const int inf=1<<30;using namespace std;struct Node{char ch; Node *left, *right;}; void Buildtree (node *&root) {Node *s = (node *) malloc (sizeof (node)); s->left = Null;s->right = null;scanf ("%c", & AMP;S->CH); if (s->ch = = ', ') {free (s); return;} root = S; Buildtree (Root->left); Buildtree (root->right);} void preorder (Node *root) {if (root = = NULL) return;printf ("%c", root->ch); Preorder (Root->left); Preorder (root->right);} void Inorder (Node *root) {if (root = NULL) Return;inorder (root->left);p rintf ("%c", root->ch); Inorder (root-> right);} void Postorder (Node *root) {if (root = NULL) return; Postorder (Root->left); Postorder (Root->righT);p rintf ("%c", Root->ch);} int main () {freopen ("In.txt", "R", stdin); Node *root; Buildtree (root); Preorder (Root);p rintf ("\ n"), inorder (root);p rintf ("\ n"); Postorder (Root);p rintf ("\ n"); return 0;}
Binary Tree First Order construction + (first order, middle order, sequential traversal)