Arrange list of int

I just took online test for C++ programmer position, it was really interesting; But for porting programmer like me -which implementing anything is mere only on memory :p – this question is really hard for me.

Here is the question :

Write a function `arrange` that can take any non-negative integer as a argument and return it with it’s digits in descending order. Descending order means that you take the highest digit and place the next highest digit immediately after it. e.g.
=> 654321

=> 9875543221

Sorting is very easy, I have a lot of premade function to handle it. Processing the number was made me numb for some minutes, I took 20 minutes to figure out how to do it – maan I’m really stupid, it’s really easy! – .

int arrange(int y)
 int b = y;
 int value[100];
 int size=0;
 int tenth = pow(10,size +1);
 value[size] = (b % tenth)/ (tenth/10);
 b -= value[size]*(tenth/10);
 for(int in=0;in<size;in++){

That’s the function I created to process numbers to array of integer, so I could sort it. Well I wrote it in hurry because I spent too much time on numbing. Look, that function is not good, there are some technique to simplify it.


2 thoughts on “Arrange list of int

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s