Maxheap and JavaFX

I was goofying around playing with different tools and languages to render images and I’ve decided to give JavaFX a try. The idea was to render a simple data structure.

So, I’ve implemented a max-heap in java and rendering code using javafx. The source code can be found here.

The max-heap implementation is straightforward and the api contains the usual suspects:

void add(int i);

/** O(n) bulk insertion. */
static MaxHeap addAll(List<Integer> xs);

/** Remove the greatest value from the heap. */
int remove();

/** Returns the sorted values in O(n lg n) in sorted . addAll. */
List<Integer> sorted();

The rendering code is more interesting and written in scala. It’s approximately 150 loc.

The main function creates a heap with random values, renders it, and finally saves the result into the file /tmp/maxheap.png

Here’s a sample output.


It’s easy to tweak the main function to generate heaps of different sizes and values.