sorting helper for heap