Use a structure that supports ordering: std :: multiset
#include <iostream> #include <set> #include <boost/lexical_cast.hpp> int main(int argc, char* argv[]) { std::multiset<int> set; for (int i = 1; i != argc; ++i) { set.insert(boost::lexical_cast<int>(argv[i])); } for (int i: set) { std::cout << i << " "; } std::cout << "\n"; }
Vocation:
$ yourprogram 1 5 4 6 7 82 6 7 8
(Note: the number of arguments is unlimited)
Matthieu M.
source share