Created
April 26, 2021 00:29
-
-
Save luizfls/fe492e9f625f25d081e433fd53f01d31 to your computer and use it in GitHub Desktop.
Heapsort without make_heap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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