Implementation of the linked list of Binary Trees (recursion)

Source: Internet
Author: User

/*************************************** * ********************************** 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 );}
    
   
  
 


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.