class BinBaum  // ------------------------------------------------
{ BinBaum links;   // linker Teilbaum
  BinBaum rechts;  // rechter Teilbaum
  int inhalt;      // Inhalt soll int sein.

  // Konstruktor
  BinBaum (int zahl)
  { this.links  = null;
    this.rechts = null;
    this.inhalt = zahl;
  }
  
  void fuegeEin (int wert)
  { if (wert < inhalt)
         { // in linken Teilbaum einfuegen
           if (links == null)
                links = new BinBaum(wert);
           else links.fuegeEin(wert);
         }
    else { // in rechten Teilbaum einfuegen
           if (rechts == null)
                rechts = new BinBaum(wert);
           else rechts.fuegeEin(wert);
         }
  } // fuegeEin


  void laufeDurch ()
  {  if (links != null) links.laufeDurch();
     Out.print(inhalt); Out.println();
     if (rechts != null) rechts.laufeDurch();
  } // laufeDurch
} // class BinBaum


class BinBaumBsp  // ---------------------------------------------
{
  static BinBaum baum;

  public static void main(String[] arg)
  { int zahl = 0;
    String muell;
    boolean baumErzeugt = false;

    Out.print("Bitte Zahlen eingeben. Ende mit -1."); Out.println();
    while (zahl != -1)
    { Out.print("Bitte Zahl eingeben: ");
      zahl = In.readInt();
      muell = In.readLine();    // CR/LF lesen
      if (!baumErzeugt)
           { baum = new BinBaum(zahl);
             baumErzeugt = true;
           }
      else {
            baum.fuegeEin(zahl);
           }
    } // while
    baum.laufeDurch();
  } // main
} // class BinBaumBsp
