public class Main{
static class Node{
char val;
Node left;
Node right;
public Node(){
this.val = '\0';
this.left = null;
this.right = null;
}
public Node(char val){
this.val = val;
this.left = null;
this.right = null;
}
}
static int index = 0;
// 根据前序遍历字符来构建一颗二叉树
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
while(scanner.hasNext()){
String dest = scanner.nextLine();
index = 0;
Node root = createTree(dest);
InfixOrder(root);
}
}
static Node createTree(String dest){
// 根 左子树 右子树
Node root = new Node(dest.charAt(index));
index++;
if(dest.charAt(index) != '#') root.left = createTree(dest);
index++;
if(dest.charAt(index) != '#') root.right = createTree(dest);
return root;
}
static void InfixOrder(Node root){
if(root == null) return;
InfixOrder(root.left);
System.out.print(root.val + " ");
InfixOrder(root.right);
}
}