Skip to content

Instantly share code, notes, and snippets.

@luizfls
Created April 26, 2021 00:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luizfls/fe492e9f625f25d081e433fd53f01d31 to your computer and use it in GitHub Desktop.
Save luizfls/fe492e9f625f25d081e433fd53f01d31 to your computer and use it in GitHub Desktop.
Heapsort without make_heap
void heapsort(std::vector<int>& v)
{
std::vector<int> u;
for(auto i : v)
{
u.push_back(i);
std::push_heap(u.begin(), u.end(), std::greater<int>{});
}
for(auto& i : v)
{
std::pop_heap(u.begin(), u.end(), std::greater<int>{});
i = u.back();
u.pop_back();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment