Wednesday, May 4, 2016

Max & Min Heap

So now that class is over and I took my final for my CS2420 class last night, I find that I have come to love programming and I miss not having an assignment to work on. So today I decided that since I had already created a Max Heap class, that I should also create a Min Heap class.

While I was working, I found that 99% of the code was going to be the same, and I didn't want to just create a copy and tweak a few lines. So instead I decided to create a abstract Heap class that I could inherit from.

So I created the base class and moved most of the code to that file. Then I made the Max and Min Heap classes and made the changes required in each class to make it work. While this also wasn't that hard, I think that it was a good exerciser. I did something similar in the Components assignment, but I think this was a much better example of how to use inheritance.

Here is my code:


That's all for now, thanks for reading!

No comments:

Post a Comment