/*
David Vajda, 7828020
Schickhardstrasse 5
D-72072, Tuebingen
https://www.ituenix.de
david@ituenix.de
*/
class BinTreeExample {
public static void main (String [] args) {
int i;
BinTree root = new BinTree (args [0]);
for (i = 1; i < args.length; i++)
root.BinTreeInsert (args [i]);
root.BinTreeTraverse ();
System.out.println(root.BinTreeContains ("Mei, mei, mei"));
System.out.println(root.BinTreeContains (args [args.length-1]));
System.out.println(root.BinTreeContains (args [0]));
}
public static class BinTree {
BinTree l;
BinTree r;
String v;
BinTree (String v) {
this.v = v;
this.r = null;
this.l = null;
}
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 BinTreeTraverse () {
BinTreeTraverse1 (" ");
return;
}
private void BinTreeTraverse1 (String optisch) {
System.out.println (optisch + this.v);
if (this.l != null)
this.l.BinTreeTraverse1 (optisch + optisch);
if (this.r != null)
this.r.BinTreeTraverse1 (optisch + optisch);
}
boolean BinTreeContains (String v) {
boolean flag1 = false, flag2 = false;
if (this.v.compareTo (v) == 0)
return true;
else {
if ((this.l == null) && (this.r == null))
return false;
if (this.l != null)
flag1 = this.l.BinTreeContains (v);
if (this.r != null)
flag2 = this.r.BinTreeContains (v);
}
return (flag1 || flag2);
}
}
}