Tutorial 12: Inner class exercises


Introduction

This tutorial serves as a drill to use anonymous inner classes in conjunction with visitors for recursive structures. Everytime you need a helper visitor, you should think of using anonymous inner classes to do the job.


Study the code and documentation for the linear recursive structure LRStruct.

1. Assume a LRStruct host contains Integer objects.  Write a visitor called GetMin to find and return the minimum Integer object in the host.

2. Assume a LRStruct host contains Integer objects.  Write a visitor called RemMin to find, remove, and returns the minimum Integer object in the host.

3. Assume a LRStruct host contains Integer objects.  Write a visitor called MoveMin2First to find the minimum Integer object in the host, move it to the front of the host, and return it.

4. Rewrite the code for EveryOther.java (given in class this morning) using inner classes.

5. Rewrite the code for MergeSorter.java (given in class this morning) using inner classes.

6. Review the binary tree structure (BiTree). Write a visitor to count the number of leaves without checking for emptiness of the subtrees. Use anonymous classes.

D. X. Nguyen, April 17, 2000
dxnguyen@cs.rice.edu