/** This class implements AVL tree. **/ import java.io.*; import java.lang.*; import java.util.*; class Tree { AVL root_=null; public Tree(){} void dump () { if (root_!= null) root_.dump(5); } void remove (Comparable o) { if (root_!= null) { root_=root_.remove(o); if (root_!= null) root_.shorter_=false; } } void add (Comparable o) { if (root_== null) root_=new AVL(o); else { root_=root_.insert(o); root_.taller_=false; } } Object find (Comparable o) { if (root_== null) return null; else { return root_.find(o); } } boolean validate () { //if the tree is empty, its valid. if (root_== null) return true; //if any nodes Balance Factor starting with the root is invalid, //return false; otherwise, continue validation. if (!root_.BFisOK()) return false; //element in root must be bigger than all elements in its left subtree and //smaller than those to its right. The same is true for every node //in our tree. Validate and return true if all is well; otherwise, //return false. if (root_.left_ != null && !root_.left_.keyOK(root_.element_,true)) return false; if (root_.right_ != null && !root_.right_.keyOK(root_.element_,false)) return false; return true; } }