point find_nearest(vector<point> vp, int s, int e, int axis, point p, point best) { if (s == e) return best; int mid = (s + e + 1) / 2; // e is 0-based vp[mid].print(); cout << endl; // if (best == NULL) { // best = vp[mid]; // } // consider the current node if (vp[mid].squaredDistance(best) < best.squaredDistance(p)) { best = vp[mid]; } // search the near branch if (p.a[axis] < vp[mid].a[axis]) best = find_nearest(vp, s, mid - 1, (axis + 1) % 2, p, best); // search the away branch - MAYBE // if () { // // } return find_nearest(vp, mid + 1, e, (axis + 1) % 2, p, best); }