I didn't look that closely but I did notice that you could possibly exceed the bounds of your vector. I haven't written a heapsort in years. C++ provides std::make_heap and std::sort_heap for such purposes.