Be sure to follow the instructions (posted on the course page) on how to enable Java applets in your web browser. If you have trouble, come see me.

All three problems relate to an applet that visualizes operations on heaps of integers. Here is a small and a big version that you can run. To run this applet on the lab machines, type

appletviewer ~schar/public_html/courses/cs201-f17/examples/Heaps/hw7Sample/HeapTest.htmlTo get started, unzip the file

HeapTest.html IntHeap.java IntTree.java RandomHeap.java HeapTest.java IntSkewHeap.java IntVectorHeap.javaThe file

Import the `hw7` directory into Eclipse as usual. Since this
program is an Applet, running it is a bit different: right-click on
the file `HeapTest.java` and select "Run As -> Java Applet".
This should open a window showing your applet, however, it might be too small.
Instead of having to resize it each time, simply close the window, then
go to "Run -> Run Configurations...", open the "Parameters" tab, and
change the Width and Height to 600 (or bigger). Now you're all set!
The next time you should be able to run the program via the green
triangle button as usual.

Note that you can also run the applet from the command line (after
you've compiled it), using the supplied file `HeapTest.html`.
If you want to try this, `cd` to your `hw7` directory and
type

appletviewer HeapTest.htmlIn this assignment, you will have to add code to the files

// Interface for heaps of integers // // CS 201 HW 7 public interface IntHeap { // returns true iff heap has no values public boolean isEmpty(); // adds value to heap public void add(int value); // removes and returns the minimum int at the root of the heap // pre: !isEmpty() public int remove(); // returns the minimum int at the root of the heap ( = Bailey's getFirst()) // pre: !isEmpty() public int value(); // removes all elements from the heap public void clear(); // The following two methods left() and right() are provided to // enable printing of the heap. They are not part of a // "traditional" heap interface, which should hide the actual heap // structure. Only the methods isEmpty(), value(), left(), and // right() should be used on sub-heaps returned by left() and // right(). The methods add() and remove() should NOT be used on // sub-heaps! // returns left "sub-heap" of heap // pre: !isEmpty() public IntHeap left(); // returns right "sub-heap" of heap // pre: !isEmpty() public IntHeap right(); }

Problem 1: Drawing the heap

public static void drawHeap(Graphics g, IntHeap h, int l, int r, int y, int dy, int rad); // Draws the heap h at height y with root centered between l and r. // The next level is drawn at height y+dy. // Each leaf is drawn as a circle with radius rad.The picture below illustrates the role of the parameters of

You will need to use drawing commands such as

g.setColor(Color.black); g.setColor(Color.yellow); g.drawLine(x1, y1, x2, y2); g.drawOval(x, y, width, height); g.fillOval(x, y, width, height);For more information and other commands, see the documentation on

Problem 2: Vector-based heaps of integers

Complete the definitions of `add()` and `remove()` in
the file `IntVectorHeap.java`. This involves adding and modifying
code from Bailey's `VectorHeap.java`.

Once your code works, you should see a heap using complete trees in the top half of the applet (as in the sample applet).

Problem 3: Skew heaps of integers

Complete the definitions of `add()` and `remove()` in
the file `IntSkewHeap.java`. This involves adding and modifying
code from Bailey's `SkewHeap.java`.

**Note:** Bailey's object-oriented implementation has two 'merge' methods.
Ignore the first one. You only need the second (static) one.

To test your code, comment out the line

hc2 = new HeapCanvas(new RandomHeap(), "Random 'Heap'");in

hc2 = new HeapCanvas(new IntSkewHeap(), "Skew Heap");You should then see a skew heap in the bottom half of the applet (as in the sample applet).