class Test
{
class BTree{
char data;
BTree left;
BTree right;
}
public void Create(BTree root,String first,String mid,int s1,int t1,int s2,int t2)
{
root.data=first.charAt(s1);
int rootpos=mid.indexOf(first.charAt(s1));
int len=rootpos-s2;
if (rootpos>s2) {
root.left=new BTree();
Create(root.left,first, mid,s1+1, s1+len, s2, rootpos-1);
}
if (rootpos<t2) {
root.right=new BTree();
Create(root.right,first, mid,s1+len+1, t1, rootpos+1, t2);
}
}
public void show(BTree root)
{
if (root.left!=null) {
show(root.left);
}
if (root.right!=null) {
show(root.right);
}
System.out.print(root.data);
}
public void run()
{
String mid="ABEDFCHG";
String first="CBADEFGH";
BTree root=new BTree();
Create(root, first, mid, 0, first.length()-1, 0, mid.length()-1);
show(root);
}
public static void main(String[] args)
{
new Test().run();
}
}