/media/sda-magnetic/david/Dokumente-15/fernuni-hagen/cs-i-ii/old-cs-2-03/java-new/2020-11-23/ParamTreeProgTest2.java


class ParamTreeProgTest2 {
    public static void main (String [] args) {
        int i;
        TreeNode <Str> root = new TreeNode <Str> (new Str(args[0]));
        
        for (i = 1;  i < args.length;  i++)
            root.treenodeInsert (new Str(args[i]));
            
        root.treenodePrint();
    }
    
    public static class Str implements Comparable {
        private String src;
        
        public Str (String src) {
            this.src = src;
        }
        
        @Override
        public int compareTo (Object o) {
            Str des = (Str) o;
            return this.src.compareTo (des.src);
        }
        @Override
        public String toString () {
            return src;
        }
    }
    
    
    public static class Person implements Comparable {
        private String firstName;
        private String lastName;

        public Person(String firstName, String lastName)    {
            this.firstName = firstName;
            this.lastName = lastName;
        }

        public String getFirstName() {
            return firstName;
        }

        public String getLastName() {
            return lastName;
        }

        @Override
        public String toString() {
            return "Person{firstName='" + firstName + "', lastName='" + lastName + "'}";
        }

        @Override
        public int compareTo(Object o) {
            Person other = (Person) o;
            return this.lastName.compareTo(other.lastName);
        }
    }
    
    public static class TreeNode <P extends Comparable> {
        TreeNode l;
        TreeNode r;
        P v;
        
        TreeNode (P v) {
            this.l = null;
            this.r = null;
            this.v = v;
        }
        
        void treenodeInsert (P v) {
            if (this.v.compareTo (v) < 0) {
                if (this.l == null)
                    this.l = new TreeNode(v);
                else
                    this.l.treenodeInsert (v);
            }
            else {
                if (this.r == null)
                    this.r = new TreeNode (v);
                else
                    this.r.treenodeInsert (v);
            }
        }
        
        void treenodePrint () {
            if (this.l != null)
                this.l.treenodePrint();
            System.out.println (this.v.toString());
            if (this.r != null)
                this.r.treenodePrint();
        }
    }
}