Sdut 3346 Data Structure Experiment binary tree Seven: leaf problem

Source: Internet
Author: User

Data structure Experiment binary tree Seven: leaf problemTime limit:1000ms Memory limit:65536kb SubmitStatisticProblem Description

A sequence of characters, such as abd,,eg,,, cf,,, ( which represents an empty node ), is known as an ordinal input. Set up the two-fork tree and output all the leaf nodes of the two-tree in order from top to bottom, from left to right.

Input data has more than one line, each line is a length less than -characters in a string. Output outputs the leaf nodes of the binary tree from top to bottom in order from left to right. Example Input
Abd,,eg,,, CF,,, Xnl,,i,,u,
Example Output
Dfguli
DQE:Water problem
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; - } -  - voidCxvisit (Tree *R) in { -Tree *que[ -]; to     intI=0, j=0; +que[j++]=R; -      while(i<j) the     { *         if(Que[i]) $         {Panax NotoginsengQue[j++]=que[i]->lt; -Que[j++]=que[i]->RT; the             if(que[i]->lt==null&&que[i]->rt==NULL) +printf"%c",que[i]->c); A         } thei++; +     } - } $  $ intMain () - { -     Charxx[ -],*p; theTree *Root; -      while(SCANF ("%s", XX)! =EOF)Wuyi     { thep=xx; -root=creat (p); Wu cxvisit (root); -printf"\ n"); About     } $     return 0; - } -  - /*************************************************** A User Name: * * * + result:accepted the Take time:0ms - Take memory:156kb $ Submit time:2016-11-03 18:43:40 the ****************************************************/

Sdut 3346 Data Structure Experiment binary tree Seven: leaf problem

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.