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