Skip to content

Instantly share code, notes, and snippets.

@LucianoPAlmeida
Last active September 13, 2018 01:45
Show Gist options
  • Save LucianoPAlmeida/63ccab7ec255ae8dbb17859c7331fe15 to your computer and use it in GitHub Desktop.
Save LucianoPAlmeida/63ccab7ec255ae8dbb17859c7331fe15 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <array>
#include <vector>
int main(int argc, const char * argv[]) {
std::vector<int> numbers = {0, 2, 1, 4, 5, -2, 4};
std::stable_sort(numbers.begin(), numbers.end(), std::greater<int>());
std::cout << "Descending: " << std::flush;
for(auto i: numbers) {
std::cout << i << " " << std::flush;
}
std::stable_sort(numbers.begin(), 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 4 2 1 0 -2
// Ascending: -2 0 1 2 4 4 5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment