public class BinTreeProg {
public static void main (String [] args) {
int i;
try {
BinTree root = new BinTree (args [0]);
for (i = 1; i < args.length; i++)
root.binTreeInsert (args [i]);
root.binTreePrint ();
}
catch (ArrayIndexOutOfBoundsException e) {
System.out.println ("Array Index Out Of Bounds");
}
}
static public class BinTree {
BinTree l = null;
BinTree r = null;
String v = null;
BinTree (String v) {
this.v = v;
this.l = l;
this.r = r;
}
void binTreeInsert (String v) {
if (this.v.compareTo (v) > 0) {
if (this.l == null)
this.l = new BinTree (v);
else
this.l.binTreeInsert (v);
}
else {
if (this.r == null)
this.r = new BinTree (v);
else
this.r.binTreeInsert (v);
}
}
void binTreePrint () {
if (this.l != null)
this.l.binTreePrint ();
System.out.println (this.v);
if (this.r != null)
this.r.binTreePrint ();
}
}
}