/media/sda-magnetic/david/Extern-Magnetic-2022-06-29/Extern01/Dokumente-2021-05-8/disk10-ab-2020-01-10/02-debian-pc2-work/informatik/java-new/2021-01-27/BinTreeProg.java


public class BinTreeProg {
    public static void main (String [] args) {
        try {
            BinTree root = new BinTree (args [0]);
            int i;
            
            for (i = 1;  i < args.length;  i++) 
                root.insert (args [i]);
            root.traverse ();
        }
        catch (ArrayIndexOutOfBoundsException e) {
            BinTree root = new BinTree ("Emil");
            root.insert ("Dora");
            root.insert ("Anton");
            root.insert ("Berta");
            root.insert ("Caesar");
            root.traverse ();
        }
    }
    
    public static class BinTree {
        BinTree l = null;
        BinTree r = null;
        String v = null;
        
        BinTree (String v) {
            this.v = v;
            this.l = null;
            this.r = null;
        }
        
        BinTree () {
            this.v = "Anton";
            this.l = null;
            this.r = null;
        }
        
        public void insert (String v) {
            if (this.v.compareTo (v) > 0) {
                if (this.l == null)
                    this.l = new BinTree (v);
                else
                    this.l.insert (v);
            }
            else {
                if (this.r == null)
                    this.r = new BinTree (v);
                else
                    this.r.insert (v);
            }
        }
                
        public void traverse () {
            if (this.l != null)
                this.l.traverse ();
            System.out.println (this.v);
            if (this.r != null)
                this.r.traverse ();
        }
    }
}