Does this sort order have a name?

Does the following sort order have a name? Based on the index, sort the list in order of proximity to this index.

Collections.sort(items, new Comparator<String>() {

         @Override
         public int compare(String o1, String o2) {

             int distanceA = (int)Math.abs(centerIndex - items.indexOf(o1));
             int distanceB = (int)Math.abs(centerIndex - items.indexOf(o2));

             int result = distanceA - distanceB;
             return result;
         }
}

So, for a list [1,2,3,4,5,6,7,8,9,10]and centerIndex of 7, the sorted list would be:[7,8,6,9,5,10,4,3,2,1]

+4
source share
1 answer

"Sort by distance" is a fully qualified name, since your method compareis a metric or a function of distance. See wikipedia

+1
source

Source: https://habr.com/ru/post/1614625/


All Articles