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


public class BinTreeParamProg {
    public static void main (String [] args) {
        try {
            BinTree <Str> root = new BinTree <Str> (new Str(args[0]));
            int i;
            
            for (i = 1;  i < args.length;  i++)
                root.insertBinTree (new Str(args[i]));
                
            root.traverseBinTree ();
        
        }
        catch (ArrayIndexOutOfBoundsException e) {
            System.out.println ("You have to give one argument");
        }
    }
    
    public static class Str implements Comparable {
        String src;
        
        Str (String src) {
            this.src = src;
        }
        
        @Override
        public int compareTo (Object o) {
            Str des = (Str) o;
            return this.src.compareTo (des.toString());
        }
        
        @Override
        public String toString () {
            return this.src;
        }
    }
    
    public static class BinTree <P extends Comparable> {
        BinTree l;
        BinTree r;
        P v;
        
        BinTree (P v) {
            this.l = null;
            this.r = null;
            this.v = v;
        }
        
        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.l != null)
                this.l.traverseBinTree ();
            System.out.println (this.v.toString());
            if (this.r != null)
                this.r.traverseBinTree ();
        }
    }
}