Example of a generic min or max binary heap. Use at your own risk.