Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
How to find a lowest value of sort?
I have an array of integers and I need to sort it low->high.
I need to know the lowest count of swapped number values, i.e :

I have 7469 -> 4697 - Lowest value is 7, as 4+6+9 is more.

7123 would be 6, as 1+2+3 < 7.

What is the algorithm?
Posted
Comments
JackDingler 4-Apr-12 13:26pm    
It looks like you more or less explained the algorithm.

LV = a < (b + c + d) ? a : (b + c + d);
YvesDaoust 23-Apr-12 10:03am    
I don't believe one can easily make sense of this problem statement.

You use the term "count" (usually meaning number of), but you compare sums (adding the values together).

And what do you call "swapped numbers" ? All of the numbers are moved during the sorts.

1 solution

looks like you want the Bubble Sort[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900