Last active
September 13, 2018 01:43
-
-
Save LucianoPAlmeida/e3b32024edffc9319d7c671d9d12f56b to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#include <iostream> | |
#include <array> | |
#include <vector> | |
int main(int argc, const char * argv[]) { | |
std::vector<int> numbers = {0, 2, 1, 4, 5, -2, 3}; | |
std::partial_sort(numbers.begin(), numbers.begin() + 4, numbers.end(), std::greater<int>()); | |
std::cout << "Descending: " << std::flush; | |
for(auto i: numbers) { | |
std::cout << i << " " << std::flush; | |
} | |
std::partial_sort(numbers.begin(), numbers.begin() + 4, numbers.end()); | |
std::cout << std::endl; | |
std::cout << "Ascending: " << std::flush; | |
for(auto i: numbers) { | |
std::cout << i << " " << std::flush; | |
} | |
std::cout << std::endl; | |
return 0; | |
} | |
// Output | |
// Descending: 5 4 3 2 0 -2 1 | |
// Ascending: -2 0 1 2 5 4 3 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment