Sdut 3341 Data structure Experiment two forks tree two: traverse the binary tree

Source: Internet
Author: User

Data structure Experiment two forks tree two: traverse the binary tree time limit:1000ms Memory limit:65536kbsubmit Statisticproblem Description

A sequence of characters of a binary tree that is known to iterate through the input, such as a abc,,de,g,,f,,, (which represents an empty node). Build a two-fork tree and traverse the two-tree in both the middle and post order ways.

Input

Enter multiple sets of data consecutively, with each set of data entering a string of less than 50 characters in length.

Output

Each set of input data corresponds to output 2 lines:
The 1th line outputs the sequential traversal sequence;
The 2nd line outputs the sequential traversal sequence.

Example Input
Abc,,de,g,,f,,,
Example Output
Cbegdfacgefdba

DQE

According to the complete sequence of binary tree to create a two-tree and in accordance with the sequential output of the sequence, the use of simple recursion can be completed, the subject is purely a water problem, identification completed.

Attached code:
1#include <iostream>2#include <cstdio>3 4 using namespacestd;5 6 structTree7 {8     CharC;9Tree *lt,*RT;Ten }; One  ATree *creat (Char*&xx) - { -     if(*xx==' /') the         returnNULL; -     if(*xx==',') -     { -xx++; +         returnNULL; -     } +Tree *r=NewTree; Ar->c=*xx++; atr->lt=creat (xx); -r->rt=creat (xx); -     returnR; - } -  - voidMout (Tree *R) in { -     if(r==NULL) to         return ; +Mout (r->LT); -printf"%c",r->c); theMout (r->RT); * } $ Panax Notoginseng voidHout (Tree *R) - { the     if(r==NULL) +         return ; AHout (r->LT); theHout (r->RT); +printf"%c",r->c); - } $  $ intMain () - { -Tree *Root; the     Charxx[ -],*p; -      while(SCANF ("%s", XX)! =EOF)Wuyi     { thep=xx; -root=creat (p); Wu mout (root); -printf"\ n"); About Hout (root); $printf"\ n"); -     } -     return 0; - } A  + /*************************************************** the User Name: * * * - result:accepted $ Take time:0ms the Take memory:156kb the Submit time:2016-11-03 17:44:34 the ****************************************************/

Sdut 3341 Data structure Experiment two forks tree two: traverse the binary tree

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.