You are given an integer 51234 (say) we need to sort the digits of a number the output will be 12345.
51234
12345
How to do it without using array ?
Sure arrays are out, but we've got a better container anyway:
void foo(unsigned i) { std::set digits; do { digits.insert(`0` + i % 10); i /= 10; while(i!=0); }
Use multiset if your input includes numbers like 887 that should be printed as 788
multiset
887
788