Problem in nearest_neighbor function

Please check this post.