# include
using namespace std;
Typedef struct TreeNode * Tree;
Struct TreeNode {
Int Element;
Tree Left;
The Tree Right;
};
Struct Stack {
The Tree Node.
Stack * Next;
};
Void Push (Tree, Stack *);
Void CreatNew (int, Tree, Stack *);
Tree, the Tree CreatNULL (Stack *);
Tree Pop (Stack *);
Void PostOrderTraversal (Tree);
Int main () {
Int node_number, node_index;
Char operation [4].
Stack * S=new Stack;
S -> Next=NULL;
The Tree root.
The root=new TreeNode.
Cin> node_number;
Cin> operation.
Cin> node_index;
Tree new_node=new TreeNode.
Root -> Left=new_node;
The root Element ->=node_index;
Push (root, S);
Tree temp=new_node;
for (int i=1; I <2 * node_number; I++) {
Cin> operation.
if (! STRCMP (operation, "Push")) {
Cin> node_index;
CreatNew (node_index, temp, S);
}
The else
Temp=CreatNULL (temp, S);
}
Temp=NULL;
PostOrderTraversal (root);
return 0;
}
Void CreatNew (int x, Tree T, Stack * S) {
Tree new_node=new TreeNode.
T -> Left=new_node;
T -> Element=x;
Push (T, S);
T=T -> Left;
}
Void Push (Tree T, Stack * S) {
Stack * temp=new Stack;
Temp -> Next=S -> Next;
S -> Next=temp;
Temp -> Node=T;
}
Tree CreatNULL (Tree T, Stack * S) {
T=NULL;
Tree poped;
Poped=Pop (S);
Tree anewnode=new TreeNode.
Anewnode=poped -> Right;
Return anewnode;
}
Tree Pop (Stack * S) {
Stack * temp;
Tree tempTree;
Temp=S -> Next;
S -> Next=temp -> Next;
TempTree=temp -> Node.
Delete (temp);
Return tempTree;
}
Void PostOrderTraversal (Tree T) {
If (T) {
PostOrderTraversal (T -> Left);
PostOrderTraversal (T -> Right);
Cout Element <"";
}
}