Computer Science & Engineering 505
Assignment 6
Due: Nov 24, 1999
This assignment should be easy, and I suggest getting it done before the
Thanksgiving vacation, since we will be done with Smalltalk and on to
functional programming. However, if you are going out of town or are
planning on being overstuffed with turkey, you can turn it in by Dec 1
without penalty.
- Write a class BinaryTree in Smalltalk that implements
implements sorted binary trees, mirroring your Java binary tree from
Assignment 5. You do not need to implement this -- a
pencil-and-paper solution, with correct semantics and
syntax that at least resembles Smalltalk, is fine. (If you have time,
though, implementing and testing your classes would increase the
educational value of this assignment.)
Your binary tree should provide the following methods:
- insert: x -- insert x into the tree
- isEmpty -- return true if this is an empty tree and
otherwise false
- do: b -- perform an inorder traversal of the tree, repeatedly
sending the block b the message value: x
with x bound to the various items in the tree.
Also, evaluating BinaryTree new should produce a correctly
initialized empty tree.
You don't need to include a delete method. Again, you don't need
to worry about synchronization issues, and don't need to make your
BinaryTree be a subclass of Collection.
- Compare Smalltalk's technique for traversing the tree with Java's with
respect to flexibility and ease of implementation.