//generated class! do not change
package example;
public class Branch<a> extends Tree<a>{

  private a element;
  private Tree<a> left;
  private Tree<a> right;

  public a getElement(){return element;}
  public Tree<a> getLeft(){return left;}
  public Tree<a> getRight(){return right;}

  public Branch(Tree<a> l,a e,Tree<a> r){
    left=l;element=e;right=r;
  }

  public int size(){return 1+getLeft().size()+getRight().size();}

  public java.util.List<a> flatten(){
    if (getLeft() instanceof Empty){ 
      java.util.List<a> result = new java.util.ArrayList<a>();
      result.add(getElement());
      result.addAll(getRight().flatten());
      return result;
    }

    Branch<a> theLeft = (Branch<a>)getLeft();
    return new Branch<a>(theLeft.getLeft()
                        ,theLeft.getElement()
                        ,new Branch<a>(theLeft.getRight()
                                      ,getElement()
                                      ,getRight()) 
                        ).flatten() ;
  }

  public static void main(String []_){
    System.out.println(
      new Branch<String>
        (new Empty<String>(),"hallo",new Empty<String>())
        .size());
    System.out.println(
      new Branch<String>
       (new Branch<String>
          (new Empty<String>(),"freches",new Empty<String>())
       ,"lüderliches"
       ,new Branch<String>
          (new Empty<String>(),"Weib",new Empty<String>())
       ).flatten());
  }
}

