Hi,
I've been searching Google (and stack overflow of course!) for a way to sort a list of integers by value, but also by an extra factor. I'm looking for some sort of algorithm to implement I suppose. So far, I have an array in Delphi 2007 that sorts the values from largest to smallest, but now I would like it to sort values that are only X number more than the previous number in the list.
For example, the values 5, 7, 25, 15 are currently sorted to 25, 15, 7, 5. The order I am trying to get now, with the X value being 5, is 25, 15, 5, 7. As you can see, the 5 and 7 haven't switched positions because there isn't a difference of more than 5 between them.
Not sure if I'm explaining this particularly well, but that's the general idea.
One more example would be the values 10, 40, 18, 20, 16, 28. Sorted, they should be 40, 28, 18, 20, 16, 10. 18, 20 and 16 haven't moved, because again, there is not more than 5 between each of the numbers.
The idea behind it is so that the item linked to the number (for example the number of times something has been ordered) isn't changing all the time because of a difference of only 1 or 2. For example, if the list of most frequently ordered paper is displayed on a web page by frequency purchased, then the order of a particular type of paper will only change for the user if it has been ordered more than five times more than the next most frequent.
Hope this makes sense, and thanks for your time!