/*************************************** * ********************************** File Name: bitree. cpp Author: yubo Mail: yuzibode@126.com Created Time: Sunday April 27, 2014 learning focus: the definition of the node, called the type, as the type of the parameter transfer; recursive understanding; **************************************** * *******************************/# include
# Include
# Include
# Include
Using namespace std; // defines the node typedef struct BiNode {char data; struct BiNode * lch; struct BiNode * rch;} BiNode, * Bitree; // * Bitree is equivalent to a custom data type. // a binary tree is created in sequence. data must be written in the form of a regular binary tree, use # To replace void Create (Bitree & T) {T = (BiNode *) malloc (sizeof (BiNode); printf ("Enter the data \ n "); scanf ("% c", & T-> data); if (T-> data = '#') T = NULL; if (T) {printf (""); Create (T-> lch); Create (T-> rch) ;}// first-order traversal (recursion) void PreOrder (Bitree T) // Why is it {if (T) {printf ("% c", T-> data); PreOrder (T-> lch ); preOrder (T-> rch) ;}// in the middle order, traverse void InOrder (Bitree T) {if (T) {InOrder (T-> lch ); printf ("% c", T-> data); InOrder (T-> rch) ;}// traverse void PostOrder (Bitree T) {if (T) {PostOrder (T-> lch); PostOrder (T-> rch); printf ("% c", T-> data) ;}} int main () {printf (" \ n"); // Bitree T; Create (T ); printf ("\ n first-order traversal \ n"); PreOrder (T); printf ("\ n middle-order traversal \ n"); InOrder (T ); printf ("\ n sequential traversal \ n"); PostOrder (T );}