CMSC 132A Lecture Notes - Lecture 36: Binary Tree, Iterator
CMSC132A Lecture 36: Binary Trees
How would we implement a binary tree? Well, here’s the node class.
Class TreeIterator<X> implements Iterator<X> {
TreeIterator(Tree <X> t) {
}
Public boolean hasNext() {
Return this.tree.accept(new TreeVisitor<X, Boolean() {
Public Boolean VisitLeaf(Leaf<X> leaf) {
Return rights.accept(new Listof(Tree<X>, Boolean();
}
Public Boolean visitCons(Cons<X>){
Return true;
}
Public X visitNode(Node<X> node) {
Return true;
}
));
}
Public X next() {
TreeVisitor<X, X> tv=new TreeVisitor<X, X>() {