The topic description tree structure is an important non-linear data structure. Tree and binary tree are the most commonly used. For a tree with at most two sub-trees at each node, it is called a binary tree. The chain storage structure of a binary tree is an important data structure, which is defined as follows: the forward and middle order traversal of a binary tree is an important algorithm that can access all nodes of a binary tree, the following lists an algorithm for first-order traversal and two middle-order traversal respectively. The first method of sequential traversal (algorithm 6.3): the second method of sequential traversal (algorithm 6.2): by reading a string, the algorithm for establishing a binary tree is as follows: in this question, A string is obtained in the first order. spaces represent empty subnodes, and uppercase letters represent node content. Create a binary tree using this string and output each non-empty node according to one of the first traversal and two middle Traversal Algorithms described in the topic. The input contains only one row and one string, S, used to create a binary tree. Ensure that S is a valid binary tree that traverses strings in sequence. The node content only has uppercase letters, and the length of S cannot exceed 100. The output of www.2cto.com consists of three lines. Each line contains a string of characters, indicating the node content obtained in the first, middle, and middle order respectively. Each letter is followed by a space. Note the line feed at the end of the line. Sample input abc de g f sample output a B c d e g f B e g d f a c B E G D F A prompt [+] *** prompt already hide, click [+] at the top to display the *** source data structure algorithm teaching question [cpp]/********************* * ************* Date: * Author: SJF0115 * question: tianqin OJ title 1485: Binary Tree linked list storage * Source: http://acmclub.com/problem.php? Id = 1485 * result: AC * Source: Data Structure algorithm teaching question * Summary: * *********************************/# include <stdio. h> # include <stdlib. h> # include <string. h> char array [101]; // Binary Tree node typedef struct BiTNode {char data; struct BiTNode * lchild, * rchild;} BiTNode, * BiTree; // create a binary tree int CreateBiTree (BiTree & T, int & index, int & n) in sequence {if (index> = n) {return 0 ;} // enter the value of the node in the binary tree in the First Order (one character). A space indicates the empty tree if (array [index] = '') {T = NULL; index ++;} Else {T = (BiTree) malloc (sizeof (BiTNode); // generate the root node T-> data = array [index]; index ++; // construct the left subtree CreateBiTree (T-> lchild, index, n); // construct the right subtree CreateBiTree (T-> rchild, index, n);} return 0 ;} // output void Visit (BiTree T) {printf ("% c", T-> data);} // first traverse void PreOrder (BiTree T) {if (T! = NULL) {// access the root node Visit (T); // access the left subnode PreOrder (T-> lchild ); // access the right subnode PreOrder (T-> rchild) ;}// traverse void InOrder (BiTree T) {if (T! = NULL) {// access the left subnode InOrder (T-> lchild); // access the root node Visit (T ); // access the right subnode InOrder (T-> rchild) ;}// traverse void PostOrder (BiTree T) {if (T! = NULL) {// access the left sub-node PostOrder (T-> lchild); // access the right sub-node PostOrder (T-> rchild ); // access the root node Visit (T);} int main () {int len, index; while (gets (array) {BiTree T; len = strlen (array ); index = 0; // create a binary tree CreateBiTree (T, index, len); // PreOrder traversal (T); printf ("\ n "); // index = 0; InOrder (T); printf ("\ n"); // index = 0; InOrder (T ); printf ("\ n");} return 0 ;} /********************************** Date- 7 * Author: SJF0115 * question: tianqin OJ question 1485: Binary Tree linked list storage * Source: http://acmclub.com/problem.php? Id = 1485 * result: AC * Source: Data Structure algorithm teaching question * Summary: * *********************************/# include <stdio. h> # include <stdlib. h> # include <string. h> char array [101]; // Binary Tree node typedef struct BiTNode {char data; struct BiTNode * lchild, * rchild;} BiTNode, * BiTree; // create a binary tree int CreateBiTree (BiTree & T, int & index, int & n) in sequence {if (index> = n) {return 0 ;} // enter the value of the node in the binary tree in the First Order (one character). A space indicates the empty tree if (array [index] = '') {T = NULL; index ++;} else {T = (BiTre E) malloc (sizeof (BiTNode); // generate the root node T-> data = array [index]; index ++; // construct the left subtree CreateBiTree (T-> lchild, index, n); // construct the right subtree CreateBiTree (T-> rchild, index, n);} return 0 ;} // output void Visit (BiTree T) {printf ("% c", T-> data);} // first traverse void PreOrder (BiTree T) {if (T! = NULL) {// access the root node Visit (T); // access the left subnode PreOrder (T-> lchild ); // access the right subnode PreOrder (T-> rchild) ;}// traverse void InOrder (BiTree T) {if (T! = NULL) {// access the left subnode InOrder (T-> lchild); // access the root node Visit (T ); // access the right subnode InOrder (T-> rchild) ;}// traverse void PostOrder (BiTree T) {if (T! = NULL) {// access the left sub-node PostOrder (T-> lchild); // access the right sub-node PostOrder (T-> rchild ); // access the root node Visit (T);} int main () {int len, index; while (gets (array) {BiTree T; len = strlen (array ); index = 0; // create a binary tree CreateBiTree (T, index, len); // PreOrder traversal (T); printf ("\ n "); // index = 0; InOrder (T); printf ("\ n"); // index = 0; InOrder (T ); printf ("\ n");} return 0 ;}