So the question is this:
Given location X and an array of locations, I want to get an array of locations that are closest to location X, in other words, sorted by closest distance.
The way I solved this is to repeat through each array the locations and calculate the distance between X and that particular location, save that distance and sort the location by distance using the comparator. Done! Is there a better way to do this? Assuming the sort is a merge sort, it should be O (n log n).
source
share