I searched Google (and the stack overflow, of course!) To sort the list of integers by value, but also an additional factor. I'm looking for some kind of algorithm to implement, I suppose. So far, I have an array in Delphi 2007 that sorts values โโfrom the largest to the smallest, but now I would like it to sort the values โโthat are only X greater than the previous number in the list.
For example, the values โโ5, 7, 25, 15 are currently sorted by 25, 15, 7, 5. The order that I am trying to get now, with an X value of 5, is 25, 15, 5, 7. As you can see , 5 and 7 do not switch positions, because there is no difference between them more than 5.
Not sure if I explain this particularly well, but what a general idea.
Another example would be 10, 40, 18, 20, 16, 28. Sorted, they should be 40, 28, 18, 20, 16, 10. 18, 20 and 16 are not moved, because again, between each from numbers no more than 5.
The idea behind this is that the item associated with the number (for example, the number of times when something was ordered) does not change all the time due to a difference of only 1 or 2. For example, if the list of most frequently ordered paper is displayed on the web page at the acquired frequency, then the order of a specific type of paper will be changed only for the user if he was ordered more than five times more than the next most frequent one.
Hope this makes sense and thanks for your time!