CMSC 132A Lecture Notes - Lecture 34: Visitor Pattern

74 views3 pages
CMSC132A Lccture 34: Midterm 2 Review
The visitor pattern has as many type parameters as your source.
Class BTExamples{
Void testBTInOrder( tester.Tester t){
BT<Integer> i=new Leaf<>();
BT<Integer> t1=
New Node<>(4, new Node<>(2,
New Node<>(1,1,i),
New Node<>(3,i,i)),
New Leaf<>());
Listof<Integer> li= new Cons<>(i, new Cons<>(2, new Cons<>(3,
New Cons<>(4, new Empty<>())))));
t.checkExpect(i.accept(new BSTInOrder<>()), new Empty<>());
t.checkExpect(t1.accept(new BTInOrder<>()), t1);
}
}
Class BTInOrder<T> implements BTVisitor<T, Listof<T>> {
Public Listof<T> visitLeaf(Leaf<T> l) {
}
}
What if we are given an element in a list and we want the position in the list?
Unlock document

This preview shows page 1 of the document.
Unlock all 3 pages and 3 million more documents.

Already have an account? Log in

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents