COM 2545 Algorithms Homework, Fall 2008
All homeworks follow the guidlines on the course homepage.
- Due Monday, September 15 by 6am
Use the BinarySearchTree test driver class that we created the first week to create an application called "TreeViewer" that draws binary search trees. TreeViewer should use a JSplitPane to hold two JPanels: one for controlling the view, and one for displaying the view. The control panel should have 4 text fields for specifying a rectangle in the display view. The fields correspond to the x and y coordinate in the display view, and the width and height of the rectangle. In this imaginary "rectangle", your tree will be drawn. Additionally, a JButton should be placed in the control panel that will draw the tree generated by your test driver when it is clicked.
To implement the drawing functionality, add a draw function to the BinarySearchTree and Node classes with the following prototype:
draw(Graphics, int, int, int, int);
where Graphics is passed in from paint, and the four ints correspond again to x, y, width, height.
When the draw button is clicked, the BinarySearchTree draw function should be called from within the view panel's paint function and the Graphics g object should be passed in. The BST draw function will then recursively call the Node's draw function to paint the required nodes.
Also do the following additional task assigned by Professor Breban:
Modify the BST and RBT classes so they all implement the following interface:
import
java.awt.*;
public
interface AlgoObject {
public AlgoObject clone();
public void draw(Graphics g,int x,int y,int w,int h);
}
and are Cloneable.
To do it correctly, of course, you need to find out what is clone and Cloneable. Use the big Java book you all have.
Last modified: 9/4/2008