#include <iostream>
using namespace std;
typedef struct node {
struct node *lChild;
struct node *rChild;
char data;
}BiTreeNode,*BiTree;
void createBiTree(BiTree &T) {
char c;
cin >> c;
if (c == '#') {
T = NULL;
return;
}
else {
T = new BiTreeNode;
T->data = c;
createBiTree(T->lChild);
createBiTree(T->rChild);
}
}
void preTraverse(BiTree T) {
if (T) {
cout << T->data << " ";
preTraverse(T->lChild);
preTraverse(T->rChild);
}
}
void midTraverse(BiTree T) {
if (T) {
midTraverse(T->lChild);
cout << T->data << " ";
midTraverse(T->rChild);
}
}
void postTraverse(BiTree T) {
if (T) {
postTraverse(T->lChild);
postTraverse(T->rChild);
cout << T->data << " ";
}
}
int total(BiTree T) {
if (T == NULL) {
return 0;
}
return total(T->lChild) + total(T->rChild) + 1;
}
int GetDepth(BiTree T) {
if (T == NULL)
return 0;
int depthLeft = GetDepth(T->lChild);
int depthRight = GetDepth(T->rChild);
return depthLeft > depthRight ? (depthLeft + 1) : (depthRight + 1);
}
int main() {
BiTree T;
createBiTree(T);
preTraverse(T);
cout << endl;
midTraverse(T);
cout << endl;
postTraverse(T);
cout << endl;
cout << total(T);
cout << endl;
cout<<GetDepth(T);
cout << endl;
system("pause");
return 0;
}