Examples with Heaps
1. Generic Heap Example

There are three files to look at for this example (in addition to ConsoleReader.java)

The Heap.java file contains the class definition of Heap, and the methods
insert, delete, buildheap as discussed in class.

A simple driver to test this implementation is in HeapTest.java It inserts randomly generated integers into a heap, and outputs the results.

Another driver, which compares how long it takes to build a heap using the two different approaches is in TimeHeap.java. For a fair comparison of the time, this driver rewrites the buildHeap method to not copy the array of objects to be heapified.

For more discussion on timing, some useful information can be found at Timing Java Code .

2. Huffman Coding Algorithm

Driver is in Huffman.java. Supporting files are:

The example reads an input string from a file called huff.txt.