This question was closed because was too localized.
I haven't understood why, this guy has posted the code and the code wasn't working. Why not let it be answered? I voted to reopen it, but could you explain why was considered too localized?
Now I know what too localized means, it could help only a strict subset of people and in a specific area. But the heapsort is a so common of an algorithm, used by everyone.