Description
已知二叉树的一个按前序遍历输入的字符序列,如abc,,de,g,,f,,, (其中,表示空结点)。请建立二叉树,并输出建立二叉树的前序遍历序列、中序遍历序列、后序遍历序列、层次遍历序列、深度、叶子数。
Input
多组测试数据,对于每组测试数据,输入一个长度小于50的按前序遍历输入的字符序列。
Output
对于每组测试数据,第1行输出其前序遍历序列、第2行输出其中序遍历序列、第3行输出其后序遍历序列、第4行输出其深度、第5行输出其叶子数。
Sample
Input
abc,,de,g,,f,,,
Output
abcdegf cbegdfa cgefdba abcdefg 5 3
#define maxSize 55
#include<iostream>
#include<bits/stdc++.h>
#include<string.h>
using namespace std;
char a[maxSize];
typedef struct node
{
char data;
struct node *l, *r;
}node;
int len, p;
node *create(node *&b)
{
p++;
if(p >= len)return NULL;
if(a[p] == ',')
{
b = NULL;
}
else
{
b = (node *)malloc(sizeof(node));
b -> data = a[p];
b -> l = b -> r &