/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/2020-12-12/BinTreeParamProg.java


public class BinTreeParamProg {
    public static void main (String [] args) {
        try {
            BinTree <Person> root = new BinTree <Person> (new Person(args[0]));
            int i;
            
            for (i = 1;  i < args.length;  i++)
                root.insertBinTree (new Person(args[i]));
            root.traverseBinTree ();
        }
        catch (ArrayIndexOutOfBoundsException e) {
            System.out.println ("usage: java BinTreeProg arg1 ...");
        }
    }
    
    public static class Person implements Comparable {
        String name;
        
        Person (String name) {
            this.name = name;
        }
        
        public int compareTo (Object o) {
            Person des = (Person) o;
            return this.name.compareTo (des.toString());
        }
        
        public String toString () {
            return this.name;
        }
    
    }
    
    public static class BinTree <P extends Comparable> {
        BinTree l;
        BinTree r;
        P v;
        
        BinTree (P v) {
            this.v = v;
            this.l = l;
            this.r = r;
        }
        
        void insertBinTree (P v) {
            if (this.v.compareTo (v) < 0) {
                if (this.l == null)
                    this.l = new BinTree (v);
                else
                    this.l.insertBinTree (v);
            }
            else {
                if (this.r == null)
                    this.r = new BinTree (v);
                else
                    this.r.insertBinTree (v);
            }
        }
        
        void traverseBinTree () {
            if (this.r != null)
                this.r.traverseBinTree ();
            System.out.println (this.v.toString());
            if (this.l != null)
                this.l.traverseBinTree ();
        
        }
    }
}