/media/sda-magnetic/david/Dok-15-2023-11-27/informatik/java/20230710/BinTreeProg.java


public class BinTreeProg {
    public static void main (String [] args) {
        Integer i;
        String s = null;
        try {
            s = args [0];
        }
        catch (ArrayIndexOutOfBoundsException e) {
            System.out.println ("Katastrophe");
            exit (1);
        }
        BinTree t = new BinTree (s);
        for (i = 1;  i < args.length;  i++)
            t.insert (args [i]);
        
        t.out ();
            
    }
    
    public static class BinTree {
        BinTree l;
        BinTree r;
        String v;
        
        BinTree (String s) {
            this.l = null;
            this.r = null;
            this.v = s;
        }
        
        public void insert (String s) {
            if (this.v.compareTo (s) < 0) {
                if (this.l == null)
                    this.l = new BinTree (s);
                else
                    this.l.insert (s);
            }
            else {
                if (this.r == null) 
                    this.r = new BinTree (s);
                else
                    this.r.insert (s);
            }
        }  
        
        public void out () {
            if (this.l != null)
                this.l.out ();
            System.out.println (this.v);
            if (this.r != null)
                this.r.out ();
        }
        
    }
}